问题
I know I can quickly dump the values of excel cells into an array like so:
object[,] values = workSheet.UsedRange.Value2 as object[,];
Can I do something similar for attributes of cells other than their values? For example, I'd like to get the cell colour, but object[,] cc = workSheet.UsedRange.Interior.Color as object[,];
results in cc
being null.
Looping through the sheet to get cell attributes takes orders of magnitude longer.
回答1:
Better late than never. Briefly, in absence of a code stub,
Save the sheet as an xml formatted file. Read the file in with an xml reader, query the xml object for styleID (or anything else you want or need). Query the styleID's for color attrbiute, and match up same to each cell. LINQ queries on xml database should need only a couple of lines to do all this.
来源:https://stackoverflow.com/questions/15888629/excel-dump-cell-attributes-to-array