Hi,
I'm trying to read an excel worksheet that has cells with decimal numbers with exponents of 2 or more.
When I read a cell that has a value of say 1002.00 in the cell, I'm getting 1002 when the code is reading the cell. In the formula bar in excel, the number is also displayed as 1002.
Here's my piece of code.
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
excelApp.Visible = true;
excelApp.ScreenUpdating = false;
excelApp.DisplayAlerts = false;
Microsoft.Office.Interop.Excel.Workbook excelWorkbook = excelApp.Workbooks.Open("C:\test.xls", 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
Microsoft.Office.Interop.Excel.Sheets excelSheets = excelWorkbook.Worksheets;
string currentSheet = "Test Data";
Microsoft.Office.Interop.Excel.Worksheet excelWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)excelSheets.get_Item(currentSheet);
Microsoft.Office.Interop.Excel.Range range = (Microsoft.Office.Interop.Excel.Range)excelWorksheet.UsedRange;
string str = (range.Cells[_row, _column] as Microsoft.Office.Interop.Excel.Range).Value2.ToString();
I've also tried the following.
object[,] values = (object[,])range.Value2;
string str = values[_row, _column].ToString();
Is there any way I can read the value as 1002.00 without changing the cell in the worksheet to Text. I want to avoid this if possible.
Thanks.