更新单元格并保存excel后,基于该单元格的公式不会重新计算 [英] After updating a cell and save excel, formulas based on this cell doesnt recalculate

查看:268
本文介绍了更新单元格并保存excel后,基于该单元格的公式不会重新计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用XML SDK来更新excel文件中的某些单元格。

Im using XML SDK to update some cells on an excel file.

用于更新给定文本的单元格的代码(并且其工作正常)。

This is the code that im using to update a cell for a given text (and its working fine).

WorksheetPart worksheetPart = GetWorksheetPartByName(spreadSheet, sheetname);

spreadSheet.WorkbookPart.Workbook.CalculationProperties.ForceFullCalculation = true;

spreadSheet.WorkbookPart.Workbook.CalculationProperties.FullCalculationOnLoad = true;

    if (worksheetPart != null)
    {
       Cell cell = GetCell(worksheetPart.Worksheet, columnName, rowIndex);
       cell.CellValue = new CellValue(text);
       cell.DataType = new EnumValue<CellValues>(CellValues.Number);
       // Save the worksheet.
       worksheetPart.Worksheet.Save();
    }

对于另一方面,我想再次打开excel文件,并获得更新来自其公式的其他单元格的值来自上一个单元格,但是即使以下行也不能执行:

For other hand now i want to open again the excel file and get the updated values from other cells whose formulas are based on the previous cell but even with the following lines im not able to do it:

spreadSheet.WorkbookPart.Workbook.CalculationProperties.ForceFullCalculation = true;

spreadSheet.WorkbookPart.Workbook.CalculationProperties.FullCalculationOnLoad = true;

你知道为什么没有得到更新的值吗?

Do you know why im not getting the updated values?

谢谢

问候。

Jose

推荐答案

对于包含公式的每个单元格执行以下函数。

Execute the below function for every cell that contains a formula.

public void ReCalcuateFormula(Cell cell)
{
    if (cell.CellFormula != null)
        cell.CellFormula.CalculateCell = new BooleanValue(true);
}

这篇关于更新单元格并保存excel后,基于该单元格的公式不会重新计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆