简体   繁体   English

打开xml查询excel单元格

[英]open xml to query excel cells

In the past, I have created a component to pass and retrieve values to/from excel using the excel libraries. 过去,我创建了一个组件,用于使用excel库传递和从excel检索值。 The good thing is that once you have your workbook in memory and modify a cell (let's call it the origin cell) all the other cells with formulas that take this origin cell value are automatically refreshed. 好的一点是,一旦你的工作簿在内存中并修改了一个单元格(我们称之为原始单元格),所有其他具有获取此原始单元格值的公式的单元格将自动刷新。

Is this possible in OpenXml? 这可能在OpenXml中吗?

As far as I see, apparently this doesn't happen in OpenXml because the excel engine is not really executed in the background, OpenXml is just a group of classes to serialize, deserialize, read etc xml files right? 据我所知,显然这在OpenXml中不会发生,因为excel引擎并不是真的在后台执行,OpenXml只是一组用于序列化,反序列化,读取等xml文件的类吗?

That's correct, Office Open XML SDK is just a set of libraries to read/write XML files. 这是正确的,Office Open XML SDK只是一组读/写XML文件的库。 It does not have any functionality for performing calculations. 它没有任何执行计算的功能。

You can specify that Excel should recalculate everything upon load by setting the following attribute, but if you need to read the new values in code (prior to re-opening in Excel) this won't help. 您可以通过设置以下属性指定Excel应在加载时重新计算所有内容,但如果您需要在代码中读取新值(在Excel中重新打开之前),这将无济于事。

<workbook> 
  <calcPr fullCalcOnLoad="1"/> 
</workbook> 

Or in code with the Office Open XML SDK.. 或者使用Office Open XML SDK编写代码。

using (var doc = SpreadsheetDocument.Open(path, false))
{
    doc.WorkbookPart.Workbook.CalculationProperties.FullCalculationOnLoad = true;
    .
    .
    .
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM