Open-XML-SDK icon indicating copy to clipboard operation
Open-XML-SDK copied to clipboard

Open-Xml-SDK cannot load document referencing not installed font when x14ac:knownFonts is present

Open the-frank opened this issue 6 years ago • 6 comments

Description

Open-Xml-SDK will throw an OpenXmlPackageException with the message "The specified package is invalid. The main part is missing." when an excel file references fonts in worksheets that are not present on the system and the tag x14ac:knownFonts is found.

Information

  • .NET Target: .Net Framework 4.7.1
  • DocumentFormat.OpenXml Version: 2.8.1 and 2.9.0

Repro We use Open-XML SDK to produce a file (with lots of data) that we give to 3rd parties scattered around the world. They edit that file and send them back for us to import (using Open-Xml SDK again).

Sometimes we have this error from the exception while loading the document using Open-Xml SDK: The specified package is invalid. The main part is missing.

If I save the file with my own Excel application (Excel 2016) prior to import it, I can import the file fine. So I've decompressed the xlsx files and compared both against each other (the one working and the one not working) The only thing that was different is the presence of the tag x14ac:knownFonts https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.fonts.knownfonts?view=openxml-2.8.1 Value of the tag is 1. If I remove the worksheet that uses the fonts found in the styles.xml, I can load the document or if I remove the "knownfonts" tag and let the worksheets that reference those fonts: Open-Xml-SDK can open the file successfully again.

Observed

The excel app that was used to save the excel is the same version than me (2016), but installed in Korean language. Two of the fonts referenced have their name in asian characters so my wild guest is that I don't have those fonts on my system, and with the presence of the knownfonts, it causes Open-Xml to die painfully when trying to load that document.

Expected

I would expect that Open-Xml don't die when loading an excel document with if that tag is found (and fonts that I don't have on my system are referenced in that excel document). Excel do not die from actually: it allow me to open the document resave it (effectively removing that infamous "knownfonts" tag.

the-frank avatar Jan 30 '19 21:01 the-frank

Can you share an example of an excel document with this? It definitely shouldn't fail to open.

twsouthwick avatar Feb 19 '19 22:02 twsouthwick

I will as soon as I clear with Legal here, what and how I can share the excel file.

the-frank avatar Feb 20 '19 14:02 the-frank

Awesome. It'll probably be used for a unit test (although we can definitely remove all PII and make it super generic) if that matters for legal purposes.

twsouthwick avatar Feb 20 '19 18:02 twsouthwick

@the-frank I'm going to close this unless you have a repro we're able to take a look at. Feel free to re-open.

twsouthwick avatar Mar 20 '20 00:03 twsouthwick

I have the same exception when trying to open word document in a docker container. locally everything works fine

dlopatin-v avatar Mar 31 '22 16:03 dlopatin-v

@dlopatin-v can you share a repro?

twsouthwick avatar Apr 05 '22 22:04 twsouthwick