Creating a word document using Open xml format
-
4 ianuarie 2012 07:22
I am trying to create a word document in the machine(office 2003 version and office 2007 reader installed) it is not generating the document(Document is blank ).
But creating the document in office 2007 version installed machine and opening the document in office 2003 installed machine, it open the document with a warning message.The difference in size clearly indicates that the document generated by the custom code in the web application using OpenXML is not following the standards, so that it misses some of the core components in the .docx file. Once this docx is opened in word 2007 and resaved, word 2007 automatically corrects the issue and this resaved document is getting opened in Office 2003 (but with warnings).
Please provide a solution on this.I have provided the dynamic html content we are using
StringBuilder
strBody = new StringBuilder ();strBody.AppendFormat(
"<html " +xmlns:o='urn:schemas-microsoft-com:office:office' "+
"xmlns:w='urn:schemas-microsoft-com:office:word'"+
"xmlns='http://www.w3.org/TR/REC-html40'>"+
"<head> <title>Generate Proposal Document</title><style type='text/css='>{0}</style>" , styleSheetContent);strBody.Append(
"<!--[if gte mso 9]>" + "<xml>"+
"<w:WordDocument>" + "<w:View>Print</w:View>"+ "<w:Zoom>100</w:Zoom>" +
"<w:Header>Test</w:Header>" +
"<w:DoNotOptimizeForBrowser/>" +
"</w:WordDocument>"+ "</xml>" +
"<![endif]-->");
strBody.Append(
"<style>" +
"<!-- /* Style Definitions */" + "@page Section1" +
" {size:8.5in 11.0in; " +
" margin:1.0in 1.25in 0.5in 1.25in ; " +
" mso-header-margin:.5in;mso-header:h1 " +
" mso-footer-margin:.5in; mso-paper-source:0;}" +
" div.Section1" + " {page:Section1;}" + "-->" +
"</style>");
strBody.Append( " <div style='mso-element:header' id=h1>"
+
"<p class=MsoHeader style='text-align:center'> Test Word Document Header " +
"</p> </div> ");
strBody.Append( "</head>");
after this we are creating the header and footer for the document and using altchunk we are placing the html content in the document and then opening it using
Response.OutputStream.Write(since we are using memory stream to avoid saving in file system)
- Editat de RajeshRamupillai 4 ianuarie 2012 08:20
- Editat de RajeshRamupillai 4 ianuarie 2012 08:26
Toate mesajele
-
4 ianuarie 2012 16:50Moderator
Hi RajeshRamupillai:
This forum is for software developers who are using the Open Specification documentation to assist them in developing systems, services, and applications that are interoperable with Microsoft products. The Open Specifications can be found at: http://msdn.microsoft.com/en-us/library/cc203350(PROT.10).aspx. Since your post does not appear to be related to the Open Specification documentation set we would appreciate it if you could try to post your question in the following forum to have a better chance of an answer:
http://social.msdn.microsoft.com/Forums/en/worddev/threads
Regards, Obaid Farooqi- Marcat ca răspuns de Obaid FarooqiMicrosoft Employee, Moderator 4 ianuarie 2012 16:50