FastExcel icon indicating copy to clipboard operation
FastExcel copied to clipboard

Cells in List have to be ordered by colum

Open AWAS666 opened this issue 3 years ago • 0 comments

Excel fails to open a generated file if you add cells in non linear order.

For example:

var cells = new List<Cell>();
cells.Add(new Cell(1, "Value1"));
cells.Add(new Cell(3, "Value3"));
cells.Add(new Cell(2, "Value2"));

This won't open in excel and excel simply suggests "repairing" the file which means deleting the whole column and you are left wondering what happend.

So you either have to order it like this:

var cells = new List<Cell>();
cells.Add(new Cell(1, "Value1"));
cells.Add(new Cell(2, "Value2"));
cells.Add(new Cell(3, "Value3"));

Or you can overwrite it like this after writing all cell data:

cells = cells.OrderBy(y => y.ColumnNumber);

AWAS666 avatar Dec 14 '22 16:12 AWAS666