Click here to Skip to main content
14,635,966 members
Rate this:
Please Sign up or sign in to 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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
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.
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100