OleDB Read Excel decimal value

廉价感情. 提交于 2019-12-31 06:01:23

问题


I am using OleDB Ace 12 to read an Excel (xslx) sheet containing a column with decimal values. When I open the Excel sheet on my PC a decimal value is correctly formatted as 1.850,50 (NLD culture with comma as decimal separator)

When I'm reading out the Excel sheet using OleDB (C#4.0), the string value of this field is always 1,850.50 (US format)

I've tried setting the Locale of the DataSet I fill, set the currentthread's culture and more, but the DataSet filled with OleDB adapter always returns US formatted decimals.

Can I change the way it formats the value when reading? Or is it always US format no matter what?


回答1:


I think you will get it US format only. You can convert it in code:

string strFloatingNumber = "24.45"; //a floating point number in English notation
double output = 0.0; //output double number which will hold the value
double.TryParse(strFloatingNumber, out output); //convert without exception - assuming no error
MessageBox.Show(output.ToString("N2", CultureInfo.CreateSpecificCulture("nl-NL")));


来源:https://stackoverflow.com/questions/3909216/oledb-read-excel-decimal-value

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