Quantcast
Channel: Open XML Format SDK forum
Viewing all articles
Browse latest Browse all 1288

Calculated dates values are not calculated on read but on save

$
0
0

I'm working on a system that reads excel sheets and parses it. Using a method like this:

            string strDoc = @"C:\Users\Public\Documents\Sheet11.xlsx";
            using (Stream stream = File.Open(strDoc, FileMode.Open))
             using (SpreadsheetDocument document = SpreadsheetDocument.Open(stream, false))
            {

                Workbook workBook = document.WorkbookPart.Workbook;
                IEnumerable<Sheet> workSheets = workBook.Descendants<Sheet>();
                SharedStringTable sharedStrings = document.WorkbookPart.SharedStringTablePart.SharedStringTable;

                var testCaseSheet = workSheets.First();
                var testCaseSheetID = testCaseSheet.Id;
                WorksheetPart testCasesSheet = (WorksheetPart)document.WorkbookPart.GetPartById(testCaseSheetID);
                var worksheet = testCasesSheet.Worksheet;

                IEnumerable<Row> dataRows =
                    from row in worksheet.Descendants<Row>()
                    //where row.RowIndex > 1
                    select row;

                foreach (Row row in dataRows)
                {
                    IEnumerable<Cell> cellValues =
                        from cell in row.Descendants<Cell>()
                        where cell.CellValue != null
                        select cell;

                    var list = cellValues.ToList();
                }
            }

The field that needs to be read is in this format:=TEXT(DATE(YEAR(TODAY())+30;MONTH(TODAY());DAY(TODAY()));"JJJJ-MM-DD"). As of today, this field which should produce 2050-12-18 instead produces (debugging the cellvalues) 2049-12-5

However - if I save this file this problem is fixed! As such, I go look into the save date which is (in retrospect not surprisingly) 2018-12-5.

I expected the formula to run when I read the file, is there any way to get the desired behaviour?



Viewing all articles
Browse latest Browse all 1288

Trending Articles