Case-sensitive problem with columns headers

Dec 19, 2012 at 4:13 PM

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?

Dec 19, 2012 at 5:51 PM

You can't have 2 columns within a table with the same name. Excel does not distinct between Casesensitive or not.

You cant event do that within Excel directly. You have to fix it, but changing the 2nd columnname.

Dec 20, 2012 at 7:21 AM
Pitterling wrote:

You can't have 2 columns within a table with the same name. Excel does not distinct between Casesensitive or not.

You cant event do that within Excel directly. You have to fix it, but changing the 2nd columnname.

You aren't right if I have such code it's possible:

            var wb = new XLWorkbook();
            IXLWorksheet ws = wb.Worksheets.Add("Name");
            ws.Cell(1, 1).Value = "CASESENSITIVE";
            ws.Cell(1, 2).Value = "casesensitive";

            ws.Range(1,1,1,2).SetAutoFilter(true);
            
            ws.Cell(2, 1).Value = "Indocin";
            ws.Cell(2, 2).Value = "David";
            ws.Cell(3, 1).Value = "Enebrel";
            ws.Cell(3, 2).Value = "Sam";
            wb.SaveAs("Excel.xlsx");
But I work with huge amount of data and approach with DataTable is much better for me.

Dec 20, 2012 at 6:23 PM

 

Well in that case, you are not working with Datatables. Of course each cell can have the same value and you can filter for values. But if you are using DataTables which act more like a Database-Table, column names must be unique.

br,Peter

Dec 21, 2012 at 1:26 PM
Pitterling wrote:

 

Well in that case, you are not working with Datatables. Of course each cell can have the same value and you can filter for values. But if you are using DataTables which act more like a Database-Table, column names must be unique.

br,Peter

Yes, you are right. But structure of files from both approach are the same (except the table style). And I want to use first approach but to have case-sensitive columns headers names that is a goal of my question. 

Dec 22, 2012 at 8:07 AM

Again, using Tables requires different Tablenames. Using List allows same Tablenames, but does not give you the benefits from tables.