Search code examples
c#excelexceldatareader

Get correct text display from excel with IExcelDataReader


tl;dr: How to get display text in excel file instead of value after convert to string.

I have an Excel file from upload control, convert it to DataSet by IExcelDataReader and select a table in it. In some cases, I got incorrect value of string with datatable.Rows[x][y].ToString().

For example, cell with text like 44.123 will return 44,123 after .ToString() method but I want exactly string 44.123. I can fix it by add ` before cell value in excel to convert it from double to string format. But I don't know when cell have that format and want do it programmatically in c# code.

Please give me some advice. Thank you!


Solution

  • Good day, try this:

    Convert.ToString("...", new CultureInfo("en-US"));
    

    Greetings