ahmedwalid05 / FastExcel

Fast Excel Reading and Writing in .Net
MIT License
335 stars 98 forks source link

Cells in List have to be ordered by colum #72

Open AWAS666 opened 1 year ago

AWAS666 commented 1 year ago

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