Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClosedXML Case-sensitiv columns headers

As example I have such code:

DataTable table = new DataTable("Name");
table.Columns.Add("CASESENSITIVE", typeof(string));
table.Columns.Add("casesensitive", typeof(string));
table.Rows.Add("Indocin", "David");
table.Rows.Add("Enebrel", "Sam");

var wb = new XLWorkbook();
wb.Worksheets.Add(table);
wb.SaveAs("Excel.xlsx");

When I open just created file I see alert: "Excel found unreadable content in Excel.xlsx ...."

If I confirm this alert excel automaticaly add "2" for "casesensitive" column.

How solve this problem?

like image 474
Igor Tabas Avatar asked May 02 '26 19:05

Igor Tabas


1 Answers

I believe you cannot have two columns that have the same name even if the case is different. ClosedXML is probably not looking for that scenario -- so you could either download the sourcecode for ClosedXML and update it, or in your code you could check for that situation yourself and make sure it does not happen (e.g. by appending numbers after any potential duplicate column names until they are no longer duplicated, etc.).

like image 143
Luther Avatar answered May 04 '26 09:05

Luther



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!