2
Vote

Repaired Records: Worksheet properties from /xl/workbook.xml part

description

When I create spreadsheet with many worksheets via my site using EPPlus, I get the following error:

Excel found unreadable content in ViewData2023_all.xlsx Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.

Then I get the Repairs popup, and when I open up the log file I see:

<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><logFileName>error094560_01.xml</logFileName><summary>Errors were detected in file 'C:\Users\xxx\Downloads\ViewData2023_all.xlsx'</summary>-<repairedRecords summary="Following is a list of repairs:"><repairedRecord>Repaired Records: Worksheet properties from /xl/workbook.xml part (Workbook)</repairedRecord></repairedRecords></recoveryLog>

Here is a sample of the code:
using (ExcelPackage package = new ExcelPackage())
            {
                foreach (Install install in Installs)
                {
                 DataWorksheet dwtest = BuildDataWorksheet(site1ID_int, install.InstallID.ToString(), StartDate, EndDate);
                    if (dwtest.DataRecords.Count > 0)
                    {

                        string worksheetName = dwtest.Name;

                        ExcelWorksheet ws = package.Workbook.Worksheets.Add(worksheetName);

                        int chssz = dwtest.ColumnHeaders.Count;

                        int worksheet_col = 0;
                        int worksheet_row = 0;
                        for (int hdr_col = 1; hdr_col <= dwtest.ColumnHeaders.Count; hdr_col++)
                        {
                            worksheet_col = hdr_col - 1;
                            ws.Cells[1, hdr_col].Value = dwtest.ColumnHeaders[worksheet_col];
                        }

                        for (int cell_row = 2; cell_row <= (dwtest.DataRecords.Count + 1); cell_row++)
                        {
                            worksheet_row = cell_row - 2;
                            for (int cell_column = 1; cell_column <= dwtest.DataRecords[worksheet_row].CellValues.Count; cell_column++)
                            {
                                worksheet_col = cell_column - 1;
                                ws.Cells[cell_row, cell_column].Value = dwtest.DataRecords[worksheet_row].CellValues[worksheet_col];
                            }
                        }
                    }  // end of if DataWorksheet has DataRecords
                }  // end of foreach

                var stream = new MemoryStream();
                package.SaveAs(stream);

                string fileName = "ViewData.xlsx";
                string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

                stream.Position = 0;
                return File(stream, contentType, fileName);
                }               
        }
Note:
  • when I open in Excel and resave the spreadsheet is fine
  • when I create a spreadsheet with one worksheet, the spreadsheet is fine
Thanks!

comments

Erwoll wrote Aug 27, 2013 at 2:31 PM

I had similar problem when opening created Excel file. We are using Excel template with several sheets with pivot tables. When the sheet with the pivot table is removed the pivotCaches node in the Workbook XML is not affected =>it still contains all pivotCache nodes even those which are related to deleted sheets.

When I deleted those pivotCache nodes from the workbook XML, Excel file was opened without the Repair popup.

MarkScott66 wrote Mar 20 at 10:17 PM

I am seeing this exact same error. Any thoughts on when a fix might be available for this issue?

TonyDaRoma wrote Mar 31 at 3:26 PM

Hi! Try this final code:

In web page, try this:

Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("content-disposition", "attachment; filename=your_file_name.xlsx")
Response.BinaryWrite(package.GetAsByteArray())
Response.End()

The last row is VERY IMPORTANT !!!

Antonio, Roma Italia