Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Writing empty Collections to Excel do not produce Headers #263

Open
cavadino2 opened this issue Jun 22, 2023 · 3 comments
Open

Writing empty Collections to Excel do not produce Headers #263

cavadino2 opened this issue Jun 22, 2023 · 3 comments

Comments

@cavadino2
Copy link

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

@mganss
Copy link
Owner

mganss commented Jun 22, 2023

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

@cavadino2
Copy link
Author

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

@mganss
Copy link
Owner

mganss commented Jun 23, 2023

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants