Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

New Post: Change header of table

$
0
0
Thank you very much for your answer. Unfortunately, it still does not work. I have illustrated an example:
 public class Test
 {
           public string Test1 { get; set; }
           public string Test2 { get; set; }
  }

public void MyTest()
{
            List<Test> testList = new List<Test>
            {
                new Test{Test1 = "T1",Test2 = "T2"},
                new Test{Test1 = "T1",Test2 = "T2"}
            };

            var wb1 = new XLWorkbook();
            var ws = wb1.Worksheets.Add("Mysheet");
            ws.Cell(1, 1).InsertTable(testList);
            wb1.SaveAs(@"C:\Test\Test1.xlsx");

            var wb2 = new XLWorkbook();
            var ws2 = wb2.Worksheets.Add("Mysheet");
            var tb2 = ws2.Cell(1, 1).InsertTable(testList);
            const string newHeader = "TestNew";
            for (int i = 0; i < tb2.Fields.Count(); i++)
            {
                tb2.Field(i).Name = string.Format("{0} {1}", newHeader, i);
            }
            wb2.SaveAs(@"C:\Test\Test2.xlsx");
}
File Test1.xlsx opens normally. Test2.xlsx opens after a repair process from excel. This is the message which excel provides:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>

-<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">

<logFileName>error195720_01.xml</logFileName>

<summary>Fehler in Datei 'C:\Test\Test2.xlsx'</summary>


-<repairedRecords summary="Die folgenden Reparaturen wurden durchgeführt:_x000d__x000a__x000d__x000a_">

<repairedRecord>Reparierte Datensätze: Tabelle von /xl/tables/table.xml-Part (Tabelle)</repairedRecord>

</repairedRecords>

</recoveryLog>
Are there some special characters which are not allowed? Or do you have any idea from where it comes?

Kind regards Alexander

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>