开发者

Query excel spreadsheet for cell format.... (percentage)

开发者 https://www.devze.com 2023-01-04 14:10 出处:网络
I am using the .Net 4.0 and excel 2003 How can i use an oledb connection to retrieve the cell format of an excel spreadsheet... I specifically want to find out if a cell column (or cell itself) is in

I am using the .Net 4.0 and excel 2003

How can i use an oledb connection to retrieve the cell format of an excel spreadsheet... I specifically want to find out if a cell column (or cell itself) is in a numeric percentage format.

I cannot seem to find this information in the GetOleDbSchemaTable method.

EX: My web app reads numbers from an excel spreadsheet. This works fine; However, if the numbers are in a percentage format, excel displays it as (fraction*100) but the actual value is a fractional decimal (1/3 = .3333..) - Excel displays as 33.33% - (Notice the decimal point).

Therefore, i need a way of distinguishing between what is a p开发者_StackOverflow社区ercentage & what is not to allow my webapp to work properly...

Any ideas? Thanks in advance.....


You might be able to get out this information with OleDbConnection.GetSchema, but I'm not sure what information you'll get for an Excel sheet with that. Documentation here.


Search the NumberFormat property of the Cell (Range) in question for a % sign.

Also, if you can get the format type, then you're looking for a format that starts with 'P', like 'P1'.

EDIT: The only way I can see is either using XML or Automation. For automation you need to use the Interop Assembly. Namespace: Microsoft.Office.Interop.Excel, Interface: DisplayFormat, Property: NumberFormat.


Can you just read the first row of data as a string and parse it looking for '%' in the string.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号