Excel: Dump cell attributes to array

∥☆過路亽.° 提交于 2019-12-12 01:02:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!