C # Excel Percent Converted to Decimal

I am reading data from an Excel worksheet. Some data are percentages, and these values ​​are automatically converted to decimal numbers - i.e. 90% → 0.90. It seems I can’t find that this does not happen. Also, aren't all the data in the rows of the Excel worksheet? So why format the number at all?

Any advice is appreciated.

Sincerely.

+5
source share
3 answers

Check the Excel worksheet - if the cells are formatted as Percentage, then the data is displayed only, for example:, 90.0%but saved as 0.9.

If you check the cell format before importing the number, you can handle any necessary conversions.

, Interop.Excel:

Range.NumberFormat , Format Cells Excel. Percentage 0.00%, decimal places, Percentage, .

enter image description here

MSDN - Range.NumberFormat

, :

Worksheet wks = new Worksheet();
String nfmt = (string)((Range)wks.Cells[1,1]).NumberFormat;

nfmt , %, , ( ), . , nfmt NULL, !

+2

- Excel. (0.9 ). - .

, , 100.

+3
ws.Cells[1, 1].NumberFormatLocal = XlConditionValueTypes.xlConditionValuePercent;
ws.Cells[1, 1].NumberFormat = "0,00%";
0
source

All Articles