OpenXML SDK: Make Excel recalculate formula

前端 未结 5 431
旧巷少年郎
旧巷少年郎 2020-11-30 06:15

I update some cells of an Excel spreadsheet through the Microsoft Office OpenXML SDK 2.0. Changing the values makes all cells containing formula that depend on the changed c

5条回答
  •  半阙折子戏
    2020-11-30 06:42

    I use this

        static void FlushCachedValues(SpreadsheetDocument doc)
        {
            doc.WorkbookPart.WorksheetParts
                .SelectMany(part => part.Worksheet.Elements())
                .SelectMany(data => data.Elements())
                .SelectMany(row => row.Elements())
                .Where(cell => cell.CellFormula != null)
                .Where(cell => cell.CellValue != null)
                .ToList()
                .ForEach(cell => cell.CellValue.Remove())
                ;
        }
    

    This flushes the cached values

    greets

提交回复
热议问题