Answered by:
How to generate docx

Question
-
User-1644805496 posted
We are generating a document using a Word 2010 XML template via VB.Net code with out using word objects.(Using Office Open XMl)
We are getting unwanted tags when we open the Word 2010 XML Template in MS Word 2003.
Please suggest how to generate document compatible for MS Word 2003 & above.
The Below code is Currently used in generating the document.
We have given the MIME Type as
Response.ContentType = "application/msword"
And pushed the below content into Response using "Binary write".
--- Sample XML template
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"><pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="512"><pkg:xmlData><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/></Relationships></pkg:xmlData></pkg:part><pkg:part pkg:name="/word/_rels/document.xml.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" .............................. etc<o:p></o:p>We have Users using different version of office.
User Y has Word 2010 , and when he generates the document from the URL, it opens successfully.
User X has Word 2003 & Compatibility Pack Office 2007 installed , when he opens the document he gets unwanted tags as shown below.
Tuesday, October 29, 2013 8:40 AM
Answers
-
User1508394307 posted
Use WordprocessingDocument.Create() and similar methods.
Read more here http://msdn.microsoft.com/en-us/library/office/ff478190.aspx
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, November 2, 2013 5:49 PM
All replies
-
User1508394307 posted
- Do you mean that you save xml content with .docx extension?
- What happens if you open your file in Word 2010, save as a new .docx document, will it be opened in Word 2003?
Tuesday, October 29, 2013 9:48 AM -
User-1644805496 posted
1. I dont save but using Response i push the xml content into a temp doc with .docx extension.
2. Yes ,I can open a Word 2010 , saved as .docx in Word 2003 machine.
but a Word 2010 Xml document, saved as .xml when opened in word 2003 machine i get unwanted tags.
Wednesday, October 30, 2013 5:37 AM -
User1508394307 posted
I think that the problem here is that you send an xml content and tell that it's a file with .docx extension. In fact, docx is more than just xml and that's the reason why you get xml structure instead of document.
You can try to play with MIME type and set instead of application/msword one of the following values
application/vnd.ms-word.document.12
application/vnd.openxmlformats-officedocument.wordprocessingml.documentor
text/xml
In case of Response.ContentType="text/xml" you might tell that extension is ".xml" and not ".docx"
Additionally, check an article here at http://msdn.microsoft.com/en-us/magazine/cc164064.aspx regarding xml docs.
Let me know if it helps.
In general, OpenXML can create real docx using WordprocessingDocument.Create(), so if you will not find any solution with xml, try to change the way you create documents.
Wednesday, October 30, 2013 6:05 AM -
User-1644805496 posted
When i tried to generate .docx, I used the below MIME type
application/vnd.ms-word.document.12
application/vnd.openxmlformats-officedocument.wordprocessingml.documenteven then i get unwanted tags when opened in 2003 and unable to open in 2010 it throws error
i have XML file in flat opc format.. i want to convert it into .docx format.
Friday, November 1, 2013 8:17 AM -
User1508394307 posted
Use WordprocessingDocument.Create() and similar methods.
Read more here http://msdn.microsoft.com/en-us/library/office/ff478190.aspx
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, November 2, 2013 5:49 PM