Question

I develop a tool that allow you to automate process of filling Excel reports with data. (using C# library OpenXML 2.0)

I spend a lot of time dealing with Excel error "Excel found unreadable content..." when open my auto-generated report. I suspect that one of the problem in bad-formated SharedStringTable Here is my xml

<x:sst count="1" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<x:si>
    <x:t>asdd</x:t>
</x:si>

and here is xml restored in Excel

<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
count="35" uniqueCount="1">
<si>
    <t>asdd</t>
</si>

What is count="35"? Is this parameter required or just to speed up file opening process?

And other suspicious difference in original and restored document is id of my SharedStringTablePart

<Relationship Type="...sharedStrings" Target="..." Id="R0fd51616d10e4c31" />

and restored is

<Relationship Id="rId6" Type=".../sharedStrings" Target="..."/>

What do you think? Can this cause a problem? I use this code to create SharedStringTablePart

var sharedTablePart = doc.WorkbookPart.SharedStringTablePart;
        if (null == sharedTablePart)
        {
            sharedTablePart = doc.WorkbookPart.AddNewPart<SharedStringTablePart>();
            sharedTablePart.SharedStringTable = new SharedStringTable();
            sharedTablePart.SharedStringTable.Count = 0;
        }
Was it helpful?

Solution

I know it's not really an answer to you, but let me tell you what I have done when creating Excel-files using #OpenXml SDK.

First,

I have not generated the Excel file in code - I have generated an Excel file in Excel and used that as a template that I update with my code.

Second,

You do know that you do not need to use the Shared strings table, right? You can generate markup that persists strings in the cells themselves and do not refer to SharedStrings at all. This makes it a lot easier to handle Excel-files and since the SharedStrings-table is designed for optimization in really huuuuuuge spreadsheets, chances are that you might not need it at all?

I cannot remember the markup off-hand. but I'd be happy to look it up for you if you are interested.

Let me know :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top