Search code examples
c#typesexceldatareader

Always Get Data as String from Excel file using ExcelDataReader


There is a cell in my Excel file containing this number: 5892101102012990 and other cells containing mixed data (also strings)
I get this cell's data like this :

var filestream = File.Open(@"D:\111XLS\File.xlsx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
var reader = ExcelReaderFactory.CreateReader(filestream);    
while (reader.Read())
{
    var intt = int.Parse(textBox1.Text);                      
    var v1 = reader.GetValue(intt);
    var v2 = reader.GetValue(intt + 3);

    listBox1.Items.Add(v1 ?? ""); 
    listBox2.Items.Add(v2 ?? "");
}

When it gets to that cell in return I have this : 5.89210110201299E+15 If I change the cell format in Excel file to Special(Excel assumes it's a Zip-code) it will return exact number but editing the Excel file is out of options.

I'm aware that I can get the data using reader.GetDouble(intt); but because of mixed content this will cause more trouble.

Any advice on some sort of option to tell ExcelDataReader to not converting 5892101102012990 to this 5.89210110201299E+15?


Solution

  • it seems that i have to answer my own question here after 14 views.

    i just tried to convert the 5.89210110201299E+15 to a normal number using this :

    Decimal.Parse("5.89210110201299E+15", NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint);
    

    i don't know if i'm about to ran into a problem later on .

    i'm still looking forward to a better solution. any advice will be appreciated.