"Repaired Records: String properties from /xl/sharedStrings.xml part (Strings)" error while opening SSRS exported excels merged using EPPlus package
Asked Answered
M

1

5

I am exporting SSRS reports into to individual excel files and I am merging them into one file using EPPlus. Merge happens successfully but I get following error when I try to open the file in Excel. I dropped report data to produce empty report but it still gives me this error. I could merge some other SSRS report files without any issue though. I wonder if there is any option or setting in EPPlus I should turn on/off.

Repaired Records: String properties from /xl/sharedStrings.xml part (Strings)

I am providing both XML files (from /xl/sharedStrings.xml after unzipping xlsx) here with before and after Excel fixed the worksheet. My apology but I am not formatting XML on purpose to retain all tags in original form.

Before Excel Repair (As is from EPPlus merged file):

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="6" uniqueCount="6"><si><r xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><rPr><b></b><i val="0"></i><strike val="0"></strike><u val="none"></u><sz val="18"></sz><color rgb="FF000000"></color><rFont val="Tahoma"></rFont></rPr><t xml:space="preserve">Data Exceptions - Warnings</t></r><r xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><rPr><b val="0"></b><i val="0"></i><strike val="0"></strike><u val="none"></u><sz val="18"></sz><color rgb="FF000000"></color><rFont val="Verdana"></rFont></rPr><t xml:space="preserve"></t></r><r xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><rPr><b></b><i val="0"></i><strike val="0"></strike><u val="none"></u><sz val="18"></sz><color rgb="FF000000"></color><rFont val="Tahoma"></rFont></rPr><t xml:space="preserve">Summary</t></r></si><si><r xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><rPr><b val="0"></b><i val="0"></i><strike val="0"></strike><u val="none"></u><sz val="10"></sz><color rgb="FF000000"></color><rFont val="Calibri"></rFont></rPr><t xml:space="preserve"> Execution Time: </t></r><r xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><rPr><b></b><i val="0"></i><strike val="0"></strike><u val="none"></u><sz val="10"></sz><color rgb="FF000000"></color><rFont val="Calibri"></rFont></rPr><t xml:space="preserve">11/14/2019 12:03:07 PM</t></r></si><si><t>Loan Number</t></si><si><t>Asset Type</t></si><si><t>Data Exception Name</t></si><si><t># Of Loans</t></si></sst>

After Excel Repair (After excel repaired the original file and saved it in Excel):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="6" uniqueCount="6"><si><t>Data Exceptions - WarningsSummary</t></si><si><r><rPr><sz val="10"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t xml:space="preserve"> Execution Time: </t></r><r><rPr><b/><sz val="10"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>11/14/2019 12:03:07 PM</t></r></si><si><t>Loan Number</t></si><si><t>Asset Type</t></si><si><t>Data Exception Name</t></si><si><t># Of Loans</t></si></sst>

Here is the code for merging Excel files in case I am missing anything here. By the way, I don't have this issue with same files merged using Office InterOp. But, I wanted to avoid using InterOp which has issues of its own. Any help/tips would be great. Thanks

    private string MergeUsingEPPlus(List<String> ExcelFiles, string resultFile)
    {
        using (ExcelPackage masterPackage = new ExcelPackage(new FileInfo(resultFile)))
        {
            foreach (var file in ExcelFiles)
            {
                using (ExcelPackage pckg = new ExcelPackage(new FileInfo(file)))
                {

                    foreach (var sheet in pckg.Workbook.Worksheets)
                    {
                        //check name of worksheet, in case that worksheet with same name already exist exception will be thrown by EPPlus
                        string workSheetName = sheet.Name;
                        foreach (var masterSheet in masterPackage.Workbook.Worksheets)
                        {
                            if (sheet.Name == masterSheet.Name)
                            {
                                workSheetName = string.Format("{0}_{1}", workSheetName, DateTime.Now.ToString("yyyyMMddhhssmmm"));
                            }
                        }

                        //add new sheet
                        masterPackage.Workbook.Worksheets.Add(workSheetName, sheet);
                    }
                }
            }

            //masterPackage.Save();
            masterPackage.SaveAs(new FileInfo(resultFile));
        }
    }
Mehala answered 14/11, 2019 at 17:38 Comment(3)
Hard to say without actually seeing the problem excel files. Have you looked at the SharedString.xml file to see if anything looks odd? Sounds like it may be some unusual characters that Epplus is not handling properly.Superscribe
Thank you for your response. I checked SharedString.XML in NotePad++ but I don't see any unusal character except for CR and LFs. I think this has somethign to do with Rich Text Formatting though. I have posted this issue here in case someone needs to look at the file before and after excel fix it. github.com/JanKallman/EPPlus/issues/583Mehala
I could open file without error if I call Cell.RichText.Clear() and Add it as a string back using Cell.RichText.Add(txt) method. I loose custom formatting on some of the cells though.Mehala
U
8

I've had the same issue. The root cause was that Microsoft Excel has a character limit of 32,767 characters in each cell and some of my values were longer.

Anyway, the reason may vary from case to case, so I'll try to describe the universal way of identifying the issue.

  1. Open the file with Excel and let him to restore the document.
  2. Save a restored copy.

Now we have two documents, one is original and one is restored by Excel. Lets use the fact that xlsx format is actually an archive.

  1. Rename original and restored files. Change extension to zip.
  2. Extract both files.
  3. Open both folders and go to file from Excel error message (xl/sharedStrings.xml)
  4. Open both files and compare them.

I use Notepad++ with Compare plugin. By the way, first comparison may show a lot of insignificant differences. You can use "replace all" feature to make them the same in both files.

  1. The difference you got after all manipulations most probably is the reason of Excel error.
Use answered 8/9, 2021 at 16:15 Comment(2)
I had this issue when exporting a xlsx via the apache POI library. It did turn out to be a string length issue, but your method helped me track down where exactly it was happening. Only thing I did different was format the XML so it wasn't one super long line which made it a bit easier to work with.Eleonoreeleoptene
Checked, Message.Substring(0, 32768) corrupts file but Message.Substring(0, 32767) not corrupts file... THANK YOUPencil

© 2022 - 2024 — McMap. All rights reserved.