I started evaluating the Excel component today morning. I wrote a simple program to see how easy it is to reading and write excel. When I tried to read a simple file (with 2 rows and 5 column values – no formatting specified), I encountered 2 problems…
1. The MaxColumn always return Maximum column count - 1 (Min returns 0). I was hoping to get the Maximum number of columns in excel
2. Cells[,].StringValue or Cells[,].Value returns atleast one junk value (always) when I loop thro’ the collection.
Are they known bugs or am I doing something wrong?
Please see the sample code below… Please let me know if I am doing anything wrong…
Excel e = new Excel();
// Tried the Open method with and without FileFormatType. Same result.
Worksheet ws = e.Worksheets;
Cells cs = ws.Cells;
int rowCount = 0, columnCount = 0;
rowCount = cs.Rows.Count ;
columnCount = cs.MaxColumn - cs.MinColumn;
System.Console.WriteLine("Rows : " + rowCount + " Columns : " + columnCount);
for (int index = 0; index < rowCount; index++)
for (int colIndex = 0; colIndex < columnCount; colIndex++)
String s = cs[index, colIndex].Value.ToString();
System.Console.WriteLine(“cell(” + index + ", " + colIndex + ") = " + s);