Skip to content
This repository was archived by the owner on Aug 19, 2024. It is now read-only.
This repository was archived by the owner on Aug 19, 2024. It is now read-only.

InsertCellInWorksheet does not work properly #30

@iMrTidy

Description

@iMrTidy

Current code will fail in different scenarios. One of them: A1, B1, AD1 are existing cells while we are trying to insert C1. I recommend to update code as follows.

This part:

Cell refCell = null;
        foreach (Cell cell in row.Elements<Cell>())
        {
            if (cell.CellReference.Value.Length, == cellReference.Length)
            {
              if (string.Compare(cell.CellReference.Value, cellReference, true) > 0)
              {
                refCell = cell;
                break;
              }
            }
        }

should be replaced by this part:

Cell refCell = null;
			foreach (var cell in row.Elements<Cell>())
			{
				if ((cell.CellReference.Value.Length == cellReference.Length && string.Compare(cell.CellReference.Value, cellReference, StringComparison.OrdinalIgnoreCase) > 0)
					|| cell.CellReference.Value.Length > cellReference.Length)
				{
					refCell = cell;
					break;
				}
			}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions