Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have an application that uses Microsoft's OpenXML SDK to generate .docx files. The latest version of Open Office can open .docx, but it won't open a file that my SDK code generates. If I open a generated file in Word and save it, then it will open in Open Office. That however doesn't really help me all that much because I want to see if I can get my application to be viable for people who don't own Word. Has anybody had any luck getting OpenXML SDK generated docs to open in Open Office?
Posted

Better late than never, maybe it will be useful for someone.

To open docx generated by ooxml sdk its needed to 'patch' docx file (docx is just a zipped folder, so it could be done manually, or by code).
1. in file '_rels/.rels' you should remove slash from 'Target' attr of 'Relationship' nodes. For example, was
'<Relationship Target="<b>/word/document.xml</b>" Id="rId1" />'
should became
'<Relationship Target="<b>word/document.xml</b>" Id="rId1" />'

2. in file 'word/_rels/document.xml.rels' you should remove '/word/' from 'Target' attr of 'Relationship' nodes. For example, was
'<Relationship Target="<b>/word/styles.xml</b>" Id="rId1" />'
should became
'<Relationship Target="<b>styles.xml</b>" Id="rId1" />'

I've found this solution for Apache OpenOffice 4.1.0, imho it should work for other versions.
 
Share this answer
 
Comments
Member 12714951 4-Nov-20 10:25am    
I had the same problem with Apache Open Office 4.1.7 and this fixed it. I also had to do the following thing;

3. in file customXml/_rels/item1.xml.rels remove /customXml/ from 'Target' attr of 'Relationship' nodes.
In that case, the solution is to compare both file and see what differs and then update your code accordingly.

OpenXML is low level so there is a lot of details that are important...

I have used OpenXML SDK 2.0 but in my case, I was generating .xlsx files. The SDK tool is a must. It will allows you to compare the content of both files. Once you know how Word "fix" your file when saving it, you will have a good idea of what might cause the problem.

It will even allows you to get the C# code required to convert the first file to the second one.

It will still be a lot of works. As mentionned, the SDK is very low level and details are important to get right.

By the way are you creating your document from scrath of you start from an existing document that you modify. This last option might be a bit easier to get right.

Also, it help a lot to just do a few small changes and compare the files before and after to see what you should do.

By the way, in my case, I have try OpenOffice but I have tried Office 2003 (with compatibility pack), 2007, 2010 and Excel viewer and some details were required in some cases but not all. For example, the viewer require that all computations are done and also recnt version of Excel.
 
Share this answer
 
v2
Comments
DannyStaten 23-Jul-11 23:19pm    
Yeah I am familiar with the productivity tool and it had saved me a lot of grief in the past. I hadn't realized it had the tool to compare files. That will definitely get me pointed in the right direction. Thanks
DannyStaten 28-Jul-11 22:55pm    
So I have done that. I even went so far as to directly copy the class that the productivity tool generated and then do very small tweaks to run the code on my generated document.

The end result is a .docx package that is a lot closer the next time I do a comparison of the files, but there are still pretty significant differences, and Open Office still won't open the file.

Some of the differences include:
In app.xml my document has all node names with ap:NodeName (e.g. <ap:temlate>) and the one that opens in Open Office has just the straight up node name.

theme.xml in my document is theme1.xml.
All my documents xml don't have standalone="yes" in the xml document node. File that ran through MS Word have standaloen="yes"

My documents have encoding in lowercase "utf-8" MS Word's file has caps "UTF-8".

Some of the relationships are in different orders in some files.

As I said, it gets the file a lot closer, but there are still things that the code generates that will not play nicely with Office. Seems quite frustrating.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900