ExcelMapper icon indicating copy to clipboard operation
ExcelMapper copied to clipboard

Writing empty Collections to Excel do not produce Headers

Open cavadino2 opened this issue 2 years ago • 3 comments

Hi, when I execute the following code:

var excel = new ExcelMapper();
var products = Enumerable.Empty<ProductRecord>().ToList();
var file = @"productssaveemptyrecord.xlsx";
//excel.SkipBlankCells = false; --> This does the magic
excel.CreateMissingHeaders = true;
excel.Save(file, products);

My Expectation is: An Excel file with one line header and no further data is Produced

What I observe: An empty Excel file is produced. Empty in a sense, that it actually does not contain any header.

Workaround: Despite any hints in the comment for the SkipBlankCells Property, Setting it to false leads to the desired behaviour.

How to fix: SkipBlankCells does affect how Excels are written. This should be reflected in the comment. I would recommend to introduce a new property to control the behaviour, if header lines or empty collections are produced.

Kind regards, Sebastian

cavadino2 avatar Jun 22 '23 12:06 cavadino2

There is the property CreateMissingHeaders. Does that work for you?

mganss avatar Jun 22 '23 17:06 mganss

I have already added it in my example to show it has no or at least not the desired effect.

cavadino2 avatar Jun 23 '23 08:06 cavadino2

Oops, I missed that, sorry. I'll add documentation to the SkipBlankCells property.

mganss avatar Jun 23 '23 18:06 mganss