1
I understand that you’re having trouble with an Excel file created using OpenXML. The file appears to be corrupted when opened in Excel, but the data is intact after the file is repaired. The log file indicates issues with the styles and cell information.
This issue might be due to Excel expecting a fully formatted file when using OpenXML1. That means just having a file with a workbook won’t suffice, it has to have the workbook, worksheets, and at least one sheet for it to open properly1.
Another common issue is not creating a new row for each iteration when adding data1. Essentially, you might be creating a single row with multiple rows inside of it1.
Here’s a simplified example of how to create a new row for each iteration:
foreach (var temp in tempList)
{
if (cellIdex == 12)
{
cellIdex = 0;
rowIdex = rowIdex + 1;
row = new Row { RowIndex = rowIdex };
sheetData.AppendChild(row);
}
cell = CreateTextCell(ColumnLetter(cellIdex), rowIdex, tempToString(), 3);
row.AppendChild(cell);
cellIdex = cellIdex + 1;
}
The most important part to note is the row = new Row {RowIndex = rowIdex};
1.
If you’re still facing issues, you might want to try using the Open XML SDK Validator to check for any errors2.
Thanks
