Here's the code I'm using, but keep on getting unreadable error when try to open the saved file with Excel 2010.
FileInfo regFile = new FileInfo(@"mysample.xlsx");
using (ExcelPackage xlPackage = new ExcelPackage(regFile))
{
ExcelWorksheet allApp = xlPackage.Workbook.Worksheets[1];
allApp.Cells[2, 1].Value = "1";
xlPackage.Save();
}
Everything works fine, and after I repair the excel file, the sheet has been changed to what I wanted, just the above error came out when I open the excel file.
I believe is the way Epplus writes xml is different from what Excel expects? Can anyone help?
Comments: I attached the exported excel file and the code snippet that was used to produce the file. Excel tells me that there are errors in "/xl/styles.xml-Part" and "/xl/worksheets/sheet1.xml-Part" public void EpPlusTest() { // template is an empty excel file, create by: explorer | right click | new | Excel file var template = new FileInfo(@"d:\epplustemplate.xlsx"); using (ExcelPackage p = new ExcelPackage(template, true)) { ExcelWorksheet ws = p.Workbook.Worksheets[1]; var roxindices = Enumerable.Range(1, 100); var columnIndices = Enumerable.Range(1, 100); foreach (var rowindex in roxindices) { foreach (var columnindex in columnIndices) { var cell = ws.Cells[rowindex, columnindex]; cell.Value = columnindex + "/" + rowindex; cell.Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous; cell.Style.Fill.PatternType = ExcelFillStyle.Solid; cell.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(rowindex * 2, columnindex * 2, 128 - rowindex)); cell.Style.Font.Color.SetColor(Color.FromArgb(128 - columnindex, columnindex * 2, rowindex * 2)); cell.Style.Border.Bottom.Style = ExcelBorderStyle.DashDot; cell.Style.Border.Top.Style = ExcelBorderStyle.DashDot; cell.Style.Border.Left.Style = ExcelBorderStyle.DashDot; cell.Style.Border.Right.Style = ExcelBorderStyle.DashDot; } } p.SaveAs(new FileInfo(@"d:\epplus_exported.xlsx")); } }
FileInfo regFile = new FileInfo(@"mysample.xlsx");
using (ExcelPackage xlPackage = new ExcelPackage(regFile))
{
ExcelWorksheet allApp = xlPackage.Workbook.Worksheets[1];
allApp.Cells[2, 1].Value = "1";
xlPackage.Save();
}
Everything works fine, and after I repair the excel file, the sheet has been changed to what I wanted, just the above error came out when I open the excel file.
I believe is the way Epplus writes xml is different from what Excel expects? Can anyone help?
Comments: I attached the exported excel file and the code snippet that was used to produce the file. Excel tells me that there are errors in "/xl/styles.xml-Part" and "/xl/worksheets/sheet1.xml-Part" public void EpPlusTest() { // template is an empty excel file, create by: explorer | right click | new | Excel file var template = new FileInfo(@"d:\epplustemplate.xlsx"); using (ExcelPackage p = new ExcelPackage(template, true)) { ExcelWorksheet ws = p.Workbook.Worksheets[1]; var roxindices = Enumerable.Range(1, 100); var columnIndices = Enumerable.Range(1, 100); foreach (var rowindex in roxindices) { foreach (var columnindex in columnIndices) { var cell = ws.Cells[rowindex, columnindex]; cell.Value = columnindex + "/" + rowindex; cell.Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous; cell.Style.Fill.PatternType = ExcelFillStyle.Solid; cell.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(rowindex * 2, columnindex * 2, 128 - rowindex)); cell.Style.Font.Color.SetColor(Color.FromArgb(128 - columnindex, columnindex * 2, rowindex * 2)); cell.Style.Border.Bottom.Style = ExcelBorderStyle.DashDot; cell.Style.Border.Top.Style = ExcelBorderStyle.DashDot; cell.Style.Border.Left.Style = ExcelBorderStyle.DashDot; cell.Style.Border.Right.Style = ExcelBorderStyle.DashDot; } } p.SaveAs(new FileInfo(@"d:\epplus_exported.xlsx")); } }