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)

    Thursday, January 5, 2012 5:36 AM

All replies

  • Hi,

         when i am trying to create a word doument in office 2007 installed machine using openxml with memory stream, i can able to create , but when i am doing the same process in office 2003 installed machine(also office 2007 reader intalled) , i am resulted in error message as "There was an error opening the file"and document is blank.

    can anyone provide a solution for this.

     

     

     

     

    Friday, January 6, 2012 10:17 AM
  • Hi Rajesh

    From the code you show us, you're not using Office Open XML. I'm not sure exactly what you are doing, but it looks like you're trying to create a document in the file format some version of Word uses when it exports to round-trip HTML.

    When you generate an Office Open XML document it doesn't matter what version of Word is installed on a machine. Word doesn't even have to be installed on the machine. But Word Open XML doesn't look like what you posted, and you certainly cannot do "using altchunk we are placing the html content in the document " to put content into a Word Open XML document.

    It wouldn't be at all surprising that two different versions of Word use different HTML vocabularies. The HTML round-trip vocabulary is not standardised or supported. So what's generated or understood by one version of Word may not work in another version of Word.


    Cindy Meister, VSTO/Word MVP
    Friday, January 6, 2012 1:09 PM
    Moderator
  • The piece of code that i have attached is actually the code to frame the page setting for the word document that i generate.Moreover i have attached the exact code where we use the open xml approach and also how we are incorporating the word document to add the header , footer and body content.my assumption is the issue with the html tag formation so i a have highlighted the code in the above post

     

    private void GenerateSampleWordDocument(stringstrBody1)


    {

    string styleSheet = "" ;

     

    //reading the style from the style sheet folder, to be applied to the doc.

    styleSheet = Server.MapPath("../Styles/GenerateProposalstyles/" + Session["StyleSheet" ].ToString());


    string styleSheetContent = System.IO.File.ReadAllText(styleSheet);


    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>");

     

     

    strBody.Append(strBody1);

     


    CreateDocument(strBody.ToString());

    }

    #region

    Create document Process

    public void CreateDocument(string htmlText)


    {


    try

    {

    string UploadFileName = string .Empty;


    string DocName = dtProposalItem.Rows[0]["ProposalDescription"].ToString().Trim();


    string[] chars = new string[] { ",", ".", "/", "!", "@", "#", "$", "%", "^", "&", "*", "\"", ";", "(", ")", ":", "|", "[", "]", "<", ">"

    };

    for (int i = 0; i < chars.Length; i++)


    {

    if

    (DocName.Contains(chars[i]))

    {

    DocName = DocName.Replace(chars[i], " " );


    }

    }

    UploadFileName = DocName + ".docx"

    ;

    System.IO.MemoryStream memStream = new System.IO.MemoryStream

    ();


    InsertItemTemplate(memStream, htmlText);


    ProcessMain(memStream, htmlText);

    SaveAs(UploadFileName, memStream, htmlText);

    }

    catch (ApplicationException

    ex)

    {

    MBUGlobalObjectAccess.MBUException.Publish(Convert.ToString(System.Reflection.MethodBase.GetCurrentMethod()), ex.ToString(), ex.Source.ToString(), ex.StackTrace.ToString(), "MBU_Error"

    );

    }

    }

    #endregion

    #region Save Document

    public void SaveAs(string fileName, System.IO.MemoryStream memStream, string

    htmlText)

    {

    Response.AppendHeader("Content-Type", "application/msword"

    );

    Response.AppendHeader("Content-Disposition: attachment; filename="

    , fileName);


    Response.OutputStream.Write(memStream.ToArray(), 0, Convert.ToInt32(memStream.Length));

     


    Response.Write(htmlText);

    Response.Flush();

    Response.End();

    }

    #endregion

    //Header and footer added to the word document using openxml and memory stream

    #region

    Merger Document Template

    private void InsertItemTemplate(System.IO.MemoryStream memStreamTemp, string

    htmlText)

    {


    try

    {

    MainDocumentPart

    mainPart;

    using (WordprocessingDocument

    wordDocument =

    WordprocessingDocument.Create(memStreamTemp, WordprocessingDocumentType

    .Document))

    {

    mainPart = wordDocument.AddMainDocumentPart();

    mainPart.Document = new DocumentFormat.OpenXml.Wordprocessing.Document

    ();

    Body body = new Body

    ();

    HeaderPart hp = mainPart.AddNewPart<HeaderPart

    >();

    string

    relId = mainPart.GetIdOfPart(hp);

    SectionProperties sectPr = new SectionProperties

    ();

    HeaderReference headerReference = new HeaderReference

    ();

    headerReference.Id = relId;

    sectPr.Append(headerReference);

    mainPart.Document.Append(sectPr);

    hp.Header = GetHeader();

    hp.Header.Save();

     

    FooterPart fp = mainPart.AddNewPart<FooterPart

    >();

    string

    relId1 = mainPart.GetIdOfPart(fp);

    SectionProperties sectPr1 = new SectionProperties

    ();

    FooterReference footerReference = new FooterReference

    ();

    footerReference.Id = relId1;

    sectPr1.Append(footerReference);

    mainPart.Document.Append(sectPr1);


    //mainPart.Document = document;

    mainPart.Document.Save();

    fp.Footer = GetFooter();

    fp.Footer.Save();

     

    mainPart.Document.AppendChild(body);

    Paragraph para = body.AppendChild(new Paragraph

    ());

    Run run = para.AppendChild(new Run

    ());

    }

    }

    catch (ApplicationException

    ex)

    {

    MBUGlobalObjectAccess.MBUException.Publish(Convert.ToString(System.Reflection.MethodBase.GetCurrentMethod()), ex.ToString(), ex.Source.ToString(), ex.StackTrace.ToString(), "MBU_Error"

    );

    }

    }

    void ProcessMain(System.IO.MemoryStream memStream, string htmtext)


    {

    using (WordprocessingDocument doc =WordprocessingDocument.Open(memStream, true))

    {

     var paras = doc.MainDocumentPart

    .Document

    .Body

    .Elements<Paragraph >().ToList();

    AppendAltChunk(doc, "AltChunkId1", htmtext);

    }

    }

    #endregion

    void AppendAltChunk(WordprocessingDocument doc, string altChunkId, string

    html)

    {

    MainDocumentPart

    mainPart = doc.MainDocumentPart;

    AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart("application/xhtml+xml", altChunkId);

    using (System.IO.Stream chunkStream = chunk.GetStream(System.IO.FileMode.Create, System.IO.FileAccess.Write))

    using (System.IO.StreamWriter stringStream = new System.IO.StreamWriter(chunkStream))

    stringStream.Write(FixEntities(html));

    AltChunk altChunk = new AltChunk

    ();

    altChunk.Id = altChunkId;

    OpenXmlElement

    last = doc.MainDocumentPart.Document

    .Body

    .Elements()

    .LastOrDefault(e => e is Paragraph || e is AltChunk

    );

    if (last == null

    )

    doc.MainDocumentPart.Document.Body.InsertAt(altChunk, 0);


    else

    last.InsertAfterSelf(altChunk);

    }

    #region Header and Footer

    //dynamic header and footer values added

    public Header GetHeader()

    {

    Header h = new Header();

    Paragraph p = new Paragraph();

    Run rRight = new Run(new PositionalTab()

    {

    Alignment = AbsolutePositionTabAlignmentValues.Right,

    RelativeTo = AbsolutePositionTabPositioningBaseValues.Margin,

    Leader = AbsolutePositionTabLeaderCharValues.None

     

    });

    Run rLeft = new Run(new PositionalTab()

    {

    Alignment = AbsolutePositionTabAlignmentValues.Left,

    RelativeTo = AbsolutePositionTabPositioningBaseValues.Margin,

    Leader = AbsolutePositionTabLeaderCharValues.None

     

    });

    Run rCenter = new Run(new PositionalTab

    ()

    {

    Alignment = AbsolutePositionTabAlignmentValues.Center,

    RelativeTo = AbsolutePositionTabPositioningBaseValues.Margin,

    Leader = AbsolutePositionTabLeaderCharValues.None

     

    });

    Text tRight = new Text();

    Text tLeft = new Text();

    Text tCenter = new Text();

    if (Session["HeaderRight"].ToString() == "{DATE}")

    {

    DateTime dt = DateTime.Now;

    tRight.Text = dt.ToShortDateString();

    }

    else if (Session["HeaderRight"].ToString() == "{TIME}")

    {

    DateTime dt = DateTime.Now;

    tRight.Text = dt.ToShortTimeString();

    }

    if (Session["HeaderLeft"].ToString() == "{DATE}"

    )

    {

    DateTime dt = DateTime.Now;

    tLeft.Text = dt.ToShortDateString();

    }

    else if (Session["HeaderLeft"].ToString() == "{TIME}")

    {

    DateTime dt = DateTime.Now;

    tLeft.Text = dt.ToShortTimeString();

    }

    if (Session["HeaderCenter"].ToString() == "{DATE}")

    {

    DateTime dt = DateTime.Now;

    tCenter.Text = dt.ToShortDateString();

    }

    else if (Session["HeaderCenter"].ToString() == "{TIME}")

    {

    DateTime dt = DateTime.Now;

    tCenter.Text = dt.ToShortTimeString();

    }

    rRight.Append(tRight);

    rLeft.Append(tLeft);

    rCenter.Append(tCenter);

    p.Append(rRight);

    p.Append(rLeft);

    p.Append(rCenter);

    h.Append(p);

    return h;

    }

    public Footer

    GetFooter()

    {

    Footer f = new Footer();

    Paragraph p = new Paragraph();

    Run rRight = new Run(new PositionalTab()

    {

    Alignment = AbsolutePositionTabAlignmentValues.Right,

    RelativeTo = AbsolutePositionTabPositioningBaseValues.Margin,

    Leader = AbsolutePositionTabLeaderCharValues.None

    });

    Run rLeft = new Run(new PositionalTab()

    {

    Alignment = AbsolutePositionTabAlignmentValues.Left,

    RelativeTo = AbsolutePositionTabPositioningBaseValues.Margin,

    Leader = AbsolutePositionTabLeaderCharValues.None

    });

    Run rCenter = new Run(new PositionalTab()

    {

    Alignment = AbsolutePositionTabAlignmentValues

    .Center,

    RelativeTo = AbsolutePositionTabPositioningBaseValues

    .Margin,

    Leader = AbsolutePositionTabLeaderCharValues.None

    });

    Text tRight = new Text();

    Text tLeft = new Text();

    Text tCenter = new Text();

     

    if (Session["FooterRight"].ToString() == "{DATE}")

    {

    DateTime dt = DateTime.Now;

    tRight.Text = dt.ToShortDateString();

    }

    else if (Session["FooterRight"].ToString() == "{TIME}")

    {

    DateTime dt = DateTime.Now;

    tRight.Text = dt.ToShortTimeString();

    }

    if (Session["FooterLeft"].ToString() == "{DATE}")

    {

    DateTime dt = DateTime.Now;

    tLeft.Text = dt.ToShortDateString();

    }

    else if (Session["FooterLeft"].ToString() == "{TIME}")

    {

    DateTime dt = DateTime.Now;

    tLeft.Text = dt.ToShortTimeString();

    }

    if (Session["FooterLeft"].ToString() == "{DATE}")

    {

    DateTime dt = DateTime.Now;

    tCenter.Text = dt.ToShortDateString();

    }

    else if (Session["FooterLeft"].ToString() == "{TIME}")

    {

    DateTime dt = DateTime.Now;

    tCenter.Text = dt.ToShortTimeString();

    }

    rRight.Append(tRight);

    rLeft.Append(tLeft);

    rCenter.Append(tCenter);

    p.Append(rRight);

    p.Append(rLeft);

    p.Append(rCenter);

    f.Append(p);

    return f;

    }

    #endregion

    }

    }

     

    Using this approach i can able to create a word  document in 2007 machine but not in 2003 machine, If this is not the rite one in what way can i generate the word document that supports both the version (office 2003 and 2007 ) using openxml.Please provide a solution.

    The compatibilty pack has been installed in the 2003 machine. I can able to open the docx created in 2007 machine in 2003 machine with a warning message.but i am not able to create the same document in office 2003 machine.

    Monday, January 9, 2012 6:26 AM
  • Hi Rajesh

    There was a radical file format change going from 2003 to 2007, and this was accentuated moving to 2010.

    At the moment, your best bet is probably to create a 2007 docx file and make sure that the Compatibiliy Pack is installed on the 2000/2002/2003 machines that should work with the document. The Compatbiliby Pack is basically a converter that will let older versions of Word open the new file format and also save to it.


    Cindy Meister, VSTO/Word MVP
    Monday, January 9, 2012 6:58 AM
    Moderator
  • The piece of code that i have attached is actually the code to frame the page setting for the word document that i generate.Moreover i have attached the exact code where we use the open xml approach and also how we are incorporating the word document to add the header , footer and body content.my assumption is the issue with the html tag formation so i a have highlighted the code in the above post

     

    private void GenerateSampleWordDocument(stringstrBody1)


    {

    string styleSheet = "" ;

     

    //reading the style from the style sheet folder, to be applied to the doc.

    styleSheet = Server.MapPath("../Styles/GenerateProposalstyles/" + Session["StyleSheet" ].ToString());


    string styleSheetContent = System.IO.File.ReadAllText(styleSheet);


    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>");

     

     

    strBody.Append(strBody1);

     


    CreateDocument(strBody.ToString());

    }

    #region

    Create document Process

    public void CreateDocument(string htmlText)


    {


    try

    {

    string UploadFileName = string .Empty;


    string DocName = dtProposalItem.Rows[0]["ProposalDescription"].ToString().Trim();


    string[] chars = new string[] { ",", ".", "/", "!", "@", "#", "$", "%", "^", "&", "*", "\"", ";", "(", ")", ":", "|", "[", "]", "<", ">"

    };

    for (int i = 0; i < chars.Length; i++)


    {

    if

    (DocName.Contains(chars[i]))

    {

    DocName = DocName.Replace(chars[i], " " );


    }

    }

    UploadFileName = DocName + ".docx"

    ;

    System.IO.MemoryStream memStream = new System.IO.MemoryStream

    ();


    InsertItemTemplate(memStream, htmlText);


    ProcessMain(memStream, htmlText);

    SaveAs(UploadFileName, memStream, htmlText);

    }

    catch (ApplicationException

    ex)

    {

    MBUGlobalObjectAccess.MBUException.Publish(Convert.ToString(System.Reflection.MethodBase.GetCurrentMethod()), ex.ToString(), ex.Source.ToString(), ex.StackTrace.ToString(), "MBU_Error"

    );

    }

    }

    #endregion

    #region Save Document

    public void SaveAs(string fileName, System.IO.MemoryStream memStream, string

    htmlText)

    {

    Response.AppendHeader("Content-Type", "application/msword"

    );

    Response.AppendHeader("Content-Disposition: attachment; filename="

    , fileName);


    Response.OutputStream.Write(memStream.ToArray(), 0, Convert.ToInt32(memStream.Length));

     


    Response.Write(htmlText);

    Response.Flush();

    Response.End();

    }

    #endregion

    //Header and footer added to the word document using openxml and memory stream

    #region

    Merger Document Template

    private void InsertItemTemplate(System.IO.MemoryStream memStreamTemp, string

    htmlText)

    {


    try

    {

    MainDocumentPart

    mainPart;

    using (WordprocessingDocument

    wordDocument =

    WordprocessingDocument.Create(memStreamTemp, WordprocessingDocumentType

    .Document))

    {

    mainPart = wordDocument.AddMainDocumentPart();

    mainPart.Document = new DocumentFormat.OpenXml.Wordprocessing.Document

    ();

    Body body = new Body

    ();

    HeaderPart hp = mainPart.AddNewPart<HeaderPart

    >();

    string

    relId = mainPart.GetIdOfPart(hp);

    SectionProperties sectPr = new SectionProperties

    ();

    HeaderReference headerReference = new HeaderReference

    ();

    headerReference.Id = relId;

    sectPr.Append(headerReference);

    mainPart.Document.Append(sectPr);

    hp.Header = GetHeader();

    hp.Header.Save();

     

    FooterPart fp = mainPart.AddNewPart<FooterPart

    >();

    string

    relId1 = mainPart.GetIdOfPart(fp);

    SectionProperties sectPr1 = new SectionProperties

    ();

    FooterReference footerReference = new FooterReference

    ();

    footerReference.Id = relId1;

    sectPr1.Append(footerReference);

    mainPart.Document.Append(sectPr1);


    //mainPart.Document = document;

    mainPart.Document.Save();

    fp.Footer = GetFooter();

    fp.Footer.Save();

     

    mainPart.Document.AppendChild(body);

    Paragraph para = body.AppendChild(new Paragraph

    ());

    Run run = para.AppendChild(new Run

    ());

    }

    }

    catch (ApplicationException

    ex)

    {

    MBUGlobalObjectAccess.MBUException.Publish(Convert.ToString(System.Reflection.MethodBase.GetCurrentMethod()), ex.ToString(), ex.Source.ToString(), ex.StackTrace.ToString(), "MBU_Error"

    );

    }

    }

    void ProcessMain(System.IO.MemoryStream memStream, string htmtext)


    {

    using (WordprocessingDocument doc =WordprocessingDocument.Open(memStream, true))

    {

     var paras = doc.MainDocumentPart

    .Document

    .Body

    .Elements<Paragraph >().ToList();

    AppendAltChunk(doc, "AltChunkId1", htmtext);

    }

    }

    #endregion

    void AppendAltChunk(WordprocessingDocument doc, string altChunkId, string

    html)

    {

    MainDocumentPart

    mainPart = doc.MainDocumentPart;

    AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart("application/xhtml+xml", altChunkId);

    using (System.IO.Stream chunkStream = chunk.GetStream(System.IO.FileMode.Create, System.IO.FileAccess.Write))

    using (System.IO.StreamWriter stringStream = new System.IO.StreamWriter(chunkStream))

    stringStream.Write(FixEntities(html));

    AltChunk altChunk = new AltChunk

    ();

    altChunk.Id = altChunkId;

    OpenXmlElement

    last = doc.MainDocumentPart.Document

    .Body

    .Elements()

    .LastOrDefault(e => e is Paragraph || e is AltChunk

    );

    if (last == null

    )

    doc.MainDocumentPart.Document.Body.InsertAt(altChunk, 0);


    else

    last.InsertAfterSelf(altChunk);

    }

    #region Header and Footer

    //dynamic header and footer values added

    public Header GetHeader()

    {

    Header h = new Header();

    Paragraph p = new Paragraph();

    Run rRight = new Run(new PositionalTab()

    {

    Alignment = AbsolutePositionTabAlignmentValues.Right,

    RelativeTo = AbsolutePositionTabPositioningBaseValues.Margin,

    Leader = AbsolutePositionTabLeaderCharValues.None

     

    });

    Run rLeft = new Run(new PositionalTab()

    {

    Alignment = AbsolutePositionTabAlignmentValues.Left,

    RelativeTo = AbsolutePositionTabPositioningBaseValues.Margin,

    Leader = AbsolutePositionTabLeaderCharValues.None

     

    });

    Run rCenter = new Run(new PositionalTab

    ()

    {

    Alignment = AbsolutePositionTabAlignmentValues.Center,

    RelativeTo = AbsolutePositionTabPositioningBaseValues.Margin,

    Leader = AbsolutePositionTabLeaderCharValues.None

     

    });

    Text tRight = new Text();

    Text tLeft = new Text();

    Text tCenter = new Text();

    if (Session["HeaderRight"].ToString() == "{DATE}")

    {

    DateTime dt = DateTime.Now;

    tRight.Text = dt.ToShortDateString();

    }

    else if (Session["HeaderRight"].ToString() == "{TIME}")

    {

    DateTime dt = DateTime.Now;

    tRight.Text = dt.ToShortTimeString();

    }

    if (Session["HeaderLeft"].ToString() == "{DATE}"

    )

    {

    DateTime dt = DateTime.Now;

    tLeft.Text = dt.ToShortDateString();

    }

    else if (Session["HeaderLeft"].ToString() == "{TIME}")

    {

    DateTime dt = DateTime.Now;

    tLeft.Text = dt.ToShortTimeString();

    }

    if (Session["HeaderCenter"].ToString() == "{DATE}")

    {

    DateTime dt = DateTime.Now;

    tCenter.Text = dt.ToShortDateString();

    }

    else if (Session["HeaderCenter"].ToString() == "{TIME}")

    {

    DateTime dt = DateTime.Now;

    tCenter.Text = dt.ToShortTimeString();

    }

    rRight.Append(tRight);

    rLeft.Append(tLeft);

    rCenter.Append(tCenter);

    p.Append(rRight);

    p.Append(rLeft);

    p.Append(rCenter);

    h.Append(p);

    return h;

    }

    public Footer

    GetFooter()

    {

    Footer f = new Footer();

    Paragraph p = new Paragraph();

    Run rRight = new Run(new PositionalTab()

    {

    Alignment = AbsolutePositionTabAlignmentValues.Right,

    RelativeTo = AbsolutePositionTabPositioningBaseValues.Margin,

    Leader = AbsolutePositionTabLeaderCharValues.None

    });

    Run rLeft = new Run(new PositionalTab()

    {

    Alignment = AbsolutePositionTabAlignmentValues.Left,

    RelativeTo = AbsolutePositionTabPositioningBaseValues.Margin,

    Leader = AbsolutePositionTabLeaderCharValues.None

    });

    Run rCenter = new Run(new PositionalTab()

    {

    Alignment = AbsolutePositionTabAlignmentValues

    .Center,

    RelativeTo = AbsolutePositionTabPositioningBaseValues

    .Margin,

    Leader = AbsolutePositionTabLeaderCharValues.None

    });

    Text tRight = new Text();

    Text tLeft = new Text();

    Text tCenter = new Text();

     

    if (Session["FooterRight"].ToString() == "{DATE}")

    {

    DateTime dt = DateTime.Now;

    tRight.Text = dt.ToShortDateString();

    }

    else if (Session["FooterRight"].ToString() == "{TIME}")

    {

    DateTime dt = DateTime.Now;

    tRight.Text = dt.ToShortTimeString();

    }

    if (Session["FooterLeft"].ToString() == "{DATE}")

    {

    DateTime dt = DateTime.Now;

    tLeft.Text = dt.ToShortDateString();

    }

    else if (Session["FooterLeft"].ToString() == "{TIME}")

    {

    DateTime dt = DateTime.Now;

    tLeft.Text = dt.ToShortTimeString();

    }

    if (Session["FooterLeft"].ToString() == "{DATE}")

    {

    DateTime dt = DateTime.Now;

    tCenter.Text = dt.ToShortDateString();

    }

    else if (Session["FooterLeft"].ToString() == "{TIME}")

    {

    DateTime dt = DateTime.Now;

    tCenter.Text = dt.ToShortTimeString();

    }

    rRight.Append(tRight);

    rLeft.Append(tLeft);

    rCenter.Append(tCenter);

    p.Append(rRight);

    p.Append(rLeft);

    p.Append(rCenter);

    f.Append(p);

    return f;

    }

    #endregion

    }

    }

     

    Using this approach i can able to create a word  document in 2007 machine but not in 2003 machine, If this is not the rite one in what way can i generate the word document that supports both the version (office 2003 and 2007 ) using openxml.Please provide a solution.

    The compatibilty pack has been installed in the 2003 machine.

    Scenario:
    While trying to create the 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.

    Is openxml compatible with both the version (office 2003 and 2007).


    Monday, January 9, 2012 10:42 AM
  • Hi Rajesh

    As I told you before, the code you show us is NOT using Open XML. It's undocumented and unsupported HTML.

    That HTML and Open XML are two completely different things. The Compatibility Pack has nothing to do with HTML; it's only for Open XML.

    You need to change your approach and generate valid Office Open XML documents, using either System.IO.Packaging or the Open XML SDK.


    Cindy Meister, VSTO/Word MVP
    Monday, January 9, 2012 11:23 AM
    Moderator
  •  

    Hi,

      Thanks for the reply, if possible can you provide a sample code that generates the word document and also  incorporating header and footer in the doc using proper openxml SDK format.

    Regards

    R.Rajesh

    Monday, January 9, 2012 6:42 PM
  • Hi R.Rajesh,

     

    Thanks for posting in the MSDN Forum.

     

    The following snippet will create a Word 2010 document with footer and head. It will have a blank document body due to I haven’t add any paragraphs in it. I hope it can help you.

      

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using DocumentFormat.OpenXml.Packaging;
    using DocumentFormat.OpenXml;
    using DocumentFormat.OpenXml.Wordprocessing;
    
    namespace FooterHeadWordDocument
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                SaveFileDialog objSaveFileDialog = new SaveFileDialog();
                objSaveFileDialog.Filter = "Word Document (*.docx)|*.docx";
                objSaveFileDialog.ShowDialog();
                string strDocumentPath = objSaveFileDialog.FileName;
                using (WordprocessingDocument objWordDocument = 
                    WordprocessingDocument.Create(strDocumentPath,
                    WordprocessingDocumentType.Document))
                {
                    MainDocumentPart objMainDocumentPart = 
                        objWordDocument.AddMainDocumentPart();
                    HeaderPart objHeadPart = 
                        objMainDocumentPart.AddNewPart<HeaderPart>();
                    Paragraph objParagraph = new Paragraph();
                    Run objRun = new Run();
                    Text objText = new Text();
                    objText.Text = "This is a header";
                    objRun.Append(objText);
                    objParagraph.Append(objRun);
                    objHeadPart.Header = new Header();
                    objHeadPart.Header.Append(objParagraph);
                    FooterPart objFootPart = 
                        objMainDocumentPart.AddNewPart<FooterPart>();
                    objFootPart.Footer = new Footer();
                    Paragraph objParagraph_1 = new Paragraph();
                    Run objRun_1 = new Run();
                    Text objText_1 = new Text();
                    objText_1.Text = "This is a footer";
                    objRun_1.Append(objText_1);
                    objParagraph_1.Append(objRun_1);
                    objFootPart.Footer.Append(objParagraph_1);
                    string strrID_1 = objMainDocumentPart.GetIdOfPart(objFootPart);
                    string strrID = objMainDocumentPart.GetIdOfPart(objHeadPart);
                    Document objDocument = new Document();
                    Body objBody = new Body();
                    SectionProperties objSectionProperties = 
                        new SectionProperties();
                    HeaderReference objHeaderReference = new HeaderReference()
                    {
                        Type = HeaderFooterValues.Default,
                        Id = strrID
                    };
                    FooterReference objFooterReference = new FooterReference()
                    {
                        Type = HeaderFooterValues.Default,
                        Id = strrID_1
                    };
                    objSectionProperties.Append(objHeaderReference);
                    objSectionProperties.Append(objFooterReference);
                    objBody.Append(objSectionProperties);
                    objDocument.Append(objBody);
                    objMainDocumentPart.Document = objDocument;
                    DocumentSettingsPart objDocumentSettingPart = 
                        objMainDocumentPart.AddNewPart<DocumentSettingsPart>();
                    objDocumentSettingPart.Settings = new Settings();
                    Compatibility objCompatibility = new Compatibility();
                    CompatibilitySetting objCompatibilitySetting = 
                        new CompatibilitySetting() 
                        { 
                            Name = CompatSettingNameValues.CompatibilityMode, 
                            Uri = "http://schemas.microsoft.com/office/word", 
                            Val = "14" 
                        };
                    objCompatibility.Append(objCompatibilitySetting);
                    objDocumentSettingPart.Settings.Append(objCompatibility);
                    Close();
                }
            }
        }
    }
    


     

      

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, January 10, 2012 10:07 AM
    Moderator
  • Tom,

         Thanks for the code. i will implement the same and get back to you with a positive result.

    Regards

    R.Rajesh

     

    Tuesday, January 10, 2012 12:28 PM
  • Hi,

         I have implement the code  and it works fine in both office 2003 and 2007.when i  added some html content in the body part, the content is displayed as a plain text in the word documentnot as a html content. I used the below code to imbed the html content. It works in office 2007 but when trying to creata a document in 2003 it is not working(document is blank). 

    string altChunkId="AltChunkId1";

    string html="<html> <head> <title></title>"+"</head> <body> Looks how cool is <font size='x-large'><b>Open Xml</b></font>. Now with <font color='red'><u>HtmlToOpenXml</u></font>,"+

    "it nevers been so easy to convert html. <p> If you like it, add me a rating on <a href='http://notesforhtml2openxml.codeplex.com'>codeplex</a>"+

     

    "</p> <hr> </body> </html>";

    void AppendAltChunk(WordprocessingDocument doc, string altChunkId, string

    html)

    {

     

    MainDocumentPart

    mainPart = doc.MainDocumentPart;

     

    AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart( "application/xhtml+xml"

    , altChunkId);

     

    using (System.IO.Stream chunkStream = chunk.GetStream(System.IO.FileMode.Create, System.IO.FileAccess

    .Write))

     

    using (System.IO.StreamWriter stringStream = new System.IO.StreamWriter

    (chunkStream))

    stringStream.Write(FixEntities(html));

     

    AltChunk altChunk = new AltChunk

    ();

    altChunk.Id = altChunkId;

     

    OpenXmlElement

    last = doc.MainDocumentPart.Document

    .Body

    .Elements()

    .LastOrDefault(e => e

    is Paragraph || e is AltChunk

    );

     

    if (last == null

    )

    doc.MainDocumentPart.Document.Body.InsertAt(altChunk, 50);

     

    else

    last.InsertAfterSelf(altChunk);  

    }

    Can you provide a solution or code to overcome this issue.

    Wednesday, January 11, 2012 7:25 AM
  • Hi RajeshRamupillai,

     

    As far as I know, that Word 2003 doesn’t use OpenXml format. So we’re not able to solve it via OpenXml SDK. It will be a solved via Word PIA.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, January 11, 2012 10:03 AM
    Moderator
  • Hi,

      I have implemented the code and be able to generate the document in both the version (office 2003 and 2007).Adding to this i need to append some html text inside the body part,when i do so the html content is getting displayed as a plain text.To overcome this i have added the below code. now i can able to add the html content and generate it only in 2007 when trying to generate the document in 2003, i am getting a blank document.

    string altChunkId="AltChunkId1";

    string html ="<html> <head> <title></title>"+ "</head> <body> Looks how cool is <font size='x-large'><b>Open Xml</b></font>. Now with <font color='red'><u>HtmlToOpenXml</u></font>,"+

    "it nevers been so easy to convert html. <p> If you like it, add me a rating on <a href='http://notesforhtml2openxml.codeplex.com'>codeplex</a>"+

    "</p> <hr> </body> </html>";

    void

     

    AppendAltChunk(WordprocessingDocument doc, string altChunkId, string

    html)

    {

     

    MainDocumentPart

    mainPart = doc.MainDocumentPart;

     

    AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart("application/xhtml+xml"

    , altChunkId);

     

    using (System.IO.Stream chunkStream = chunk.GetStream(System.IO.FileMode.Create, System.IO.FileAccess

    .Write))

     

    using (System.IO.StreamWriter stringStream = new System.IO.StreamWriter

    (chunkStream))

    stringStream.Write(FixEntities(html));

     

     

    AltChunk altChunk = new AltChunk

    ();

    altChunk.Id = altChunkId;

     

    OpenXmlElement

    last = doc.MainDocumentPart.Document

    .Body

    .Elements()

    .Last()

    .LastOrDefault(e => e

    is Paragraph || e is AltChunk

    );

     

    if (last == null

    )

    doc.MainDocumentPart.Document.Body.InsertAt(altChunk, 0);

     

    else

    last.InsertAfterSelf(altChunk);

     

    }

    Can you please provide a solution or code for this.

    Wednesday, January 11, 2012 10:47 AM
  • Hi Tom,

          Sorry i dint referesh this page for a while,so i dint see your reply.i posted back the same query.  

    my question is how to append html content to the word document using openxml.

    do i need to raise it in different blog.

    Please do the needful

    Regards

    R.Rajesh

     

    Wednesday, January 11, 2012 10:59 AM
  • Hi R. Rajesh,

    Instead of altChunk here is the XML you can create programmatically. The hyperlink to the Codeplex web site is in the highlighted section, below. At the top of that section of XML there is a <Hyperlink tag to r:rid7. The actual url is in the part named 'document.xml.rels' which is the relationships file for the part named 'document.xml'. The contents of the rels file is in the third post.

    <w:p w:rsidR="004538A6" w:rsidRDefault="004538A6">

    <w:pPr>

    <w:rPr>

    <w:color w:val="000000" w:themeColor="text1"/>

    </w:rPr>

    </w:pPr>

    <w:r>

    <w:t xml:space="preserve">Look how cool </w:t>

    </w:r>

    <w:r w:rsidRPr="004538A6">

    <w:rPr>

    <w:sz w:val="28"/>

    </w:rPr>

    <w:t>XML</w:t>

    </w:r>

    <w:r>

    <w:rPr>

    <w:sz w:val="24"/>

    </w:rPr>

    <w:t xml:space="preserve"> </w:t>

    </w:r>

    <w:r>

    <w:t xml:space="preserve">is. Now with </w:t>

    </w:r>

    <w:proofErr w:type="spellStart"/>

    <w:r w:rsidRPr="004538A6">

    <w:rPr>

    <w:color w:val="FF0000"/>

    </w:rPr>

    <w:t>HTMLtoOpenXML</w:t>

    </w:r>

    <w:proofErr w:type="spellEnd"/>

    <w:r>

    <w:rPr>

    <w:color w:val="FF0000"/>

    </w:rPr>

    <w:t xml:space="preserve"> </w:t>

    </w:r>

    <w:r w:rsidRPr="004538A6">

    <w:rPr>

    <w:color w:val="000000" w:themeColor="text1"/>

    </w:rPr>

    <w:t xml:space="preserve">it never has been </w:t>

    </w:r>

    <w:r>

    <w:rPr>

    <w:color w:val="000000" w:themeColor="text1"/>

    </w:rPr>

    <w:t xml:space="preserve">so easy to </w:t>

    </w:r>

    <w:proofErr w:type="spellStart"/>

    <w:r>

    <w:rPr>

    <w:color w:val="000000" w:themeColor="text1"/>

    </w:rPr>

    <w:t>converthtml</w:t>

    </w:r>

    <w:proofErr w:type="spellEnd"/>

    <w:r>

    <w:rPr>

    <w:color w:val="000000" w:themeColor="text1"/>

    </w:rPr>

    <w:t xml:space="preserve">. </w:t>

    </w:r>

    </w:p>

    Regards,
    Chris Jensen
    Senior Technical Support Lead

     

     

     

     

     


    Chris Jensen
    Friday, January 13, 2012 10:52 PM
    Moderator
  • Hi R.Rajesh,

     

    Here is part 2

       

    <w:p w:rsidR="004538A6" w:rsidRPr="004538A6" w:rsidRDefault="004538A6">

          <w:r>

            <w:rPr>

              <w:color w:val="000000" w:themeColor="text1"/>

            </w:rPr>

            <w:t xml:space="preserve">If you like it </w:t>

          </w:r>

          <w:proofErr w:type="gramStart"/>

          <w:r>

            <w:rPr>

              <w:color w:val="000000" w:themeColor="text1"/>

            </w:rPr>

            <w:t>add</w:t>

          </w:r>

          <w:proofErr w:type="gramEnd"/>

          <w:r>

            <w:rPr>

              <w:color w:val="000000" w:themeColor="text1"/>

            </w:rPr>

            <w:t xml:space="preserve"> me a rating on</w:t>

          </w:r>

          <w:hyperlink r:id="rId7" w:history="1">

            <w:r w:rsidRPr="00932E54">

              <w:rPr>

                <w:rStyle w:val="Hyperlink"/>

              </w:rPr>

              <w:t xml:space="preserve"> </w:t>

            </w:r>

            <w:proofErr w:type="spellStart"/>

            <w:r w:rsidR="00932E54" w:rsidRPr="00932E54">

              <w:rPr>

                <w:rStyle w:val="Hyperlink"/>

              </w:rPr>

              <w:t>Codeplex</w:t>

            </w:r>

            <w:proofErr w:type="spellEnd"/>

            <w:r w:rsidR="00932E54" w:rsidRPr="00932E54">

              <w:rPr>

                <w:rStyle w:val="Hyperlink"/>

              </w:rPr>

              <w:t>.</w:t>

            </w:r>

          </w:hyperlink>

     

    Regards,
    Chris Jensen

     


    Chris Jensen
    Friday, January 13, 2012 10:57 PM
    Moderator
  • Hi R. Rajesh,

    Here is part 3

    In the document.xml.rels Relationships file you will need to enter the appropriate
    <Relationship such as the one highlighted below.

    <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">

      <Relationship Id="rId8" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" Target="header1.xml"/>

      <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/>

      <Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="http://notesforhtmltoopenxml.Codeplex.com" TargetMode="External"/>

      <Relationship Id="rId2" Type="http://schemas.microsoft.com/office/2007/relationships/stylesWithEffects" Target="stylesWithEffects.xml"/>

      <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>

      <Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes" Target="endnotes.xml"/>

      <Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" Target="footnotes.xml"/>

      <Relationship Id="rId10" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>

      <Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings" Target="webSettings.xml"/>

      <Relationship Id="rId9" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Target="fontTable.xml"/>

    </Relationships>

     

    The easiest way to see what you need to stream into your code when building an Office XML document programmatically is to create a real sample, save it as a .DOCX or  XLSX document, rename it by adding .zip to the file name, then unzip it so you can see the parts. That’s how the information above was generated.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “unmark as answer” if a marked post does not actually answer your question. This will help other members to find the solution easily..

    Regards,
    Chris Jensen
    Senior Technical Support Lead


    Chris Jensen
    Friday, January 13, 2012 10:59 PM
    Moderator
  • Hi,

       Thanks for the reply.i am clear about the process you explained.but how can i append the html content  programmatically without any issue (should able to create the document in 2007 as well as 2003(compatibility pack installed)  machine. I am using a process that i have attached in the above post.i work fine in 2007 but not in 2003.is there any problem in code. can you review this.

     

    Regards

    R.Rajesh

     

    Saturday, January 14, 2012 3:10 AM
  •  

    Hi ,

        Is there any way to insert the html content to the body part of the document which supports both 2003 and 2007.this is the code i am using for document generation.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using DocumentFormat.OpenXml.Packaging;
    using DocumentFormat.OpenXml;
    using DocumentFormat.OpenXml.Wordprocessing;

    namespace FooterHeadWordDocument
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                SaveFileDialog objSaveFileDialog = new SaveFileDialog();
                objSaveFileDialog.Filter = "Word Document (*.docx)|*.docx";
                objSaveFileDialog.ShowDialog();
                string strDocumentPath = objSaveFileDialog.FileName;
                using (WordprocessingDocument objWordDocument =
                    WordprocessingDocument.Create(strDocumentPath,
                    WordprocessingDocumentType.Document))
                {
                    MainDocumentPart objMainDocumentPart =
                        objWordDocument.AddMainDocumentPart();
                    HeaderPart objHeadPart =
                        objMainDocumentPart.AddNewPart<HeaderPart>();
                    Paragraph objParagraph = new Paragraph();
                    Run objRun = new Run();
                    Text objText = new Text();
                    objText.Text = "This is a header";
                    objRun.Append(objText);
                    objParagraph.Append(objRun);
                    objHeadPart.Header = new Header();
                    objHeadPart.Header.Append(objParagraph);
                    FooterPart objFootPart =
                        objMainDocumentPart.AddNewPart<FooterPart>();
                    objFootPart.Footer = new Footer();
                    Paragraph objParagraph_1 = new Paragraph();
                    Run objRun_1 = new Run();
                    Text objText_1 = new Text();
                    objText_1.Text = "This is a footer";
                    objRun_1.Append(objText_1);
                    objParagraph_1.Append(objRun_1);
                    objFootPart.Footer.Append(objParagraph_1);
                    string strrID_1 = objMainDocumentPart.GetIdOfPart(objFootPart);
                    string strrID = objMainDocumentPart.GetIdOfPart(objHeadPart);
                    Document objDocument = new Document();
                    Body objBody = new Body();
                    SectionProperties objSectionProperties =
                        new SectionProperties();
                    HeaderReference objHeaderReference = new HeaderReference()
                    {
                        Type = HeaderFooterValues.Default,
                        Id = strrID
                    };
                    FooterReference objFooterReference = new FooterReference()
                    {
                        Type = HeaderFooterValues.Default,
                        Id = strrID_1
                    };
                    objSectionProperties.Append(objHeaderReference);
                    objSectionProperties.Append(objFooterReference);
                    objBody.Append(objSectionProperties);
                    objDocument.Append(objBody);
                    objMainDocumentPart.Document = objDocument;
                    DocumentSettingsPart objDocumentSettingPart =
                        objMainDocumentPart.AddNewPart<DocumentSettingsPart>();
                    objDocumentSettingPart.Settings = new Settings();
                    Compatibility objCompatibility = new Compatibility();
                    CompatibilitySetting objCompatibilitySetting =
                        new CompatibilitySetting()
                        {
                            Name = CompatSettingNameValues.CompatibilityMode,
                            Uri = "http://schemas.microsoft.com/office/word",
                            Val = "14"
                        };
                    objCompatibility.Append(objCompatibilitySetting);
                    objDocumentSettingPart.Settings.Append(objCompatibility);
                    Close();
                }
            }
        }
    }

    Regards

    R.Rajesh

    Saturday, January 14, 2012 3:16 AM
  • Hi R. Rajesh,

    Here’s a suggestion: :

    In Microsoft Word 2010 or 2007 open the document created by your code.  

    In the body enter some text.
    Next enter a friendly name for a web site.
    Select the text for that name.
    On the Ribbon “Insert” tab navigate to the “Link” group and click the Hyperlink button.
    At the bottom of the dialog box enter the web address of the site.
    Save and close your .DOCX document.

    In the folder c:\ProgramFiles\Open XML SDK\V2.0\Tools click and run OpenXmlSdkTool.exe.

    That opens a window entitled Open XML SDK 2.0 Productivity Tool for Microsoft Office.

    Click the button “Open File”
    Browse to the document you created in Word,.

    This opens a tree.  The tope node is the name of the document – e.g. MyTesst.docx. Select that.

    Click the button “Reflect Code”

    The C# code for the entire document is in the Reflected Code pane.

    As an alternative, reflect the code in he /word/document.xml node. This will narrow down the search for how to add text and hyperlinks to the document.

    When your program builds the document you use for testing, save it.  On a system where Microsoft Word 2003 is installed with the compatibility pack open your test docx document.

    Please share your results here.

    Please click “Mark as answer” if this post helps you solve your problem

    Regards,
    Chris Jensen
    Senior Technical Support Lead

     


    Chris Jensen
    Tuesday, January 17, 2012 11:49 PM
    Moderator