【发布时间】:2017-02-28 12:00:18
【问题描述】:
我正在使用 DocumentFormat.OpenXml 读取 Excel 电子表格。用于从 SharedStringTable 对象中查找单元格值的代码存在性能瓶颈(它似乎是某种单元格值的查找表):
var returnValue = sharedStringTablePart.SharedStringTable.ChildElements.GetItem(parsedValue).InnerText;
我创建了一个字典以确保我只检索一次值:
if (dictionary.ContainsKey(parsedValue))
{
return dictionary[parsedValue];
}
var fetchedValue = sharedStringTablePart.SharedStringTable.ChildElements.GetItem(parsedValue).InnerText;
dictionary.Add(parsedValue, fetchedValue);
return fetchedValue;
这已将执行时间缩短了近 50%。然而,我的指标表明,从SharedStringTable 对象获取值的代码行执行 123,951 次仍需要 208 秒。有没有其他方法可以优化这个操作?
【问题讨论】: