I'm using DocumentFormat.OpenXml
to read an Excel spreadsheet. I have a performance bottleneck with the code used to look up the cell value from the SharedStringTable
object (it seems to be some sort of lookup table for cell values):
var returnValue = sharedStringTablePart.SharedStringTable.ChildElements.GetItem(parsedValue).InnerText;
I've created a dictionary to ensure I only retrieve a value once:
if (dictionary.ContainsKey(parsedValue))
{
return dictionary[parsedValue];
}
var fetchedValue = sharedStringTablePart.SharedStringTable.ChildElements.GetItem(parsedValue).InnerText;
dictionary.Add(parsedValue, fetchedValue);
return fetchedValue;
This has cut down the performance time by almost 50%. However my metrics indicate that it still takes 208 seconds for the line of code fetching the value from the SharedStringTable
object to execute 123,951 times. Is there any other way of optimising this operation?