2
votes

I'm creating a spreadsheet with the OpenXML SDK. The spreadsheet has several worksheets, styles, etc.

  • When I open the file in Excel, it renders fine, with no errors, and displaying all cell formats and data correctly.
  • When I open the file on a mobile device, depending on the app, I get errors that indicate the file is corrupt, or missing altogether.

I opened the .xlsx file in Excel and saved it off to another file; then I did a diff on the directory structures inside the corresponding zip files. I noticed:

  • The new copy (the copy that went through Excel) now renders properly on all tested mobile apps.
  • Only the new copy includes:
    • /docProps
    • /xl/theme
    • docProps/app.xml
    • docProps.core.xml
    • docProps/theme1.xml
  • Only the old copy includes:
    • /xl/worksheets/_rels/
    • sheet#.xml.rels
  • Modified files:
    • sheet#.xml
    • sharedStrings.xml
    • styles.xml
    • workbook.xml
    • [Content_Types].xml

What do I need to do to this file prior to saving to resolve these conflicts?

1
Maybe you don't save some parts of the xlsx file you create. Excel can habdle it and display the file, but some other editors are just not capable to read the files without them. This is just a guess though. - Lukasz M
I'm creating two Fonts, a Border, a CellStyleFormat, several Fills, and several CellFormats to correlate them to the cells, all including the required defaults. Other than the obvious Worksheets and parts and such, what else is required? Where do these _rels items go? - tsilb
Make sure you separately save the stylesheet (if you added any) by calling spreadsheet.WorkbookPart.WorkbookStylesPart.Stylesheet.Save();. - Lukasz M
Yup, I see my style info in the styles file - and it opens and displays correctly in Excel itself. - tsilb
It's good you've found a solution. However, I suppose using a template file as a base could fix this issue as well (and it would not require using interop). - Lukasz M

1 Answers

1
votes

The problem seems to be the relationship URIs. See this question for a similar problem:

OpenXML spreadsheet created in .NET won't open in iPad

The biggest issue is that the worksheet XML files have to be "sheet1.xml" instead of "/xl/sheet1.xml", as with other relevant XML files.