Bugs? or Am I doing something wrong?

Hi,

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.
// I used the Excel2003 to create the Book1.xls file
e.Open(@“D:\temp\Asposetest\Book1.xls”, FileFormatType.Excel2003);

Worksheet ws = e.Worksheets[0];

Cells cs = ws.Cells;

int rowCount = 0, columnCount = 0;

rowCount = cs.Rows.Count ;
//Bug 1 : MaxColumn is always Maximum number of columns - 1
// If I increment the count by one by adding +1 here the loop below
// crashes…



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++)

{
// I get a junk value for atleast one cell. Please see the attached image file

String s = cs[index, colIndex].Value.ToString();

System.Console.WriteLine(“cell(” + index + ", " + colIndex + ") = " + s);

}


Regarding #1 : Adding +1 to the MaxColumn seems to work fine after I put null object conditions in the for loop.

#2 problem still occurs. any solution?

Thanks,
Sankar S.

Dear Sankar,

These two issues are not bugs.

1. MaxColumn property returns maximum column index of cell which contains data or style. MinColumn property returns minimum column index of cell which contains data or style. They are all zero based. In your file, the data are from column A to column D, right? So the MinColumn returns 0 and MaxColumn returns 3. The column count should be

columnCount = cells.MaxColumn - cells.MinColumn + 1;

2. The random text are license warning. Please check

for reference.