Bug in method WorksheetWriter.FindCell(...) !

Jul 1, 2009 at 11:48 AM

 

// Cells must be in sequential order according to CellReference. Determine where to insert the new cell.
Cell refCell = null;
foreach (Cell cell in row.Elements<Cell>())
{
    if ((string.Compare(cell.CellReference.Value, cellReference, true) > 0))
    {
        refCell = cell;
        break;
    }
}

When we determine where to insert the new cell,

we are not allowed to use string.Compare() method.

When we use string.Compare(), we have "Z" > "AA" !!!

To fix this bug, we must compare not column names, but column indexes.

like this:

 

// Cells must be in sequential order according to CellReference. Determine where to insert the new cell.
Cell refCell = null;
foreach (Cell cell in row.Elements<Cell>())
{
    string colName = SpreadsheetReader.ColumnFromReference(cell.CellReference.Value);
    string colName2 = SpreadsheetReader.ColumnFromReference(cellReference);

    if (SpreadsheetReader.GetColumnIndex(colName) > SpreadsheetReader.GetColumnIndex(colName2))
    {
        refCell = cell;
        break;
    }
}

 

 

 

Coordinator
Jul 13, 2009 at 11:21 PM

Fixed in latest release.