【发布时间】:2015-08-31 15:55:21
【问题描述】:
我正在使用以下代码作为更大项目的一部分 - 该程序基本上根据从下拉框中选择的工作表读取电子表格 - 然后将结果分配给数据表 - 我有一个 for 循环运行以下函数来获取单元格内容并将其添加到数据表中
public string GetValue(Cell cell, SharedStringTablePart stringTablePart)
{
if (cell.ChildElements.Count == 0) return null;
//get cell value
string value = cell.ElementAt(0).InnerText;//CellValue.InnerText;
//Look up real value from shared string table
if ((cell.DataType != null) && (cell.DataType == CellValues.SharedString))
value = stringTablePart.SharedStringTable.ChildElements[Int32.Parse(value)].InnerText;
return value;
}
在我使用的电子表格中,这会返回一个公式而不是结果。电子表格公式是 =Sheet1!A12,本质上,用户在 Sheet1 A12 中输入的任何内容都应显示在单元格中。现在电子表格已经填写了信息,但程序不会只提取公式的结果。
这方面的一个例子是:Sheet 1 A12 包含单词“Dog”,这意味着在 Sheet2 中,单元格 A4 具有公式 =Sheet1A12 并且应该显示“Dog”(它在 excel 中显示,但在程序中没有) .
考虑到结果已经存在,OpenXML 是否能够显示结果?
【问题讨论】: