none
Creating a word document using Open xml format RRS feed

  • Question

  • 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)

    Wednesday, January 4, 2012 7:22 AM

Answers