C# read data from excel file results in ###

.net, c#, excel, range, worksheet

Solution

Try using `Range.Value` property instead of `Text`.

So instead of

(range.Cells[rCnt, cCnt] as Range).Text;

you would write

(range.Cells[rCnt, cCnt] as Range).Value;

Problem

i read data from an excel file with this code ``` Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; Microsoft.Office.Interop.Excel.Range range; int rCnt = 0; int cCnt = 0; string[,] data; xlWorkSheet = (Worksheet)wb.Worksheets.get_Item(sheetId); range = xlWorkSheet.UsedRange; data = new string[range.Rows.Count, range.Columns.Count]; for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++) { for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++) { data[rCnt - 1, cCnt - 1] = (string) (range.Cells[rCnt, cCnt] as Range).Text; } } ``` Now i am running sometimes into cells where the value in excel is displayed as ### because the column space is not big enough to display the number. In excel of course i can see the right value in the line on the top when i click on the cell but in my program i am getting the ### as value instead of the right number. Any advice here?

Original source