none
add header to word file RRS feed

  • Question

  • hi i am able to export the flowdocument into the word file successfully. But may i know how to add a header to the exported word document also? 
    Change
    • Moved by Jie BaoModerator Friday, August 20, 2010 2:38 AM office dev (From:Windows Presentation Foundation (WPF))
    • Moved by Cindy Meister MVPModerator Wednesday, August 25, 2010 7:54 AM OpenXML, not Word-Developer (From:Word for Developers)
    Thursday, August 19, 2010 11:09 AM

All replies

  • ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = "This text is in the primary header of the first section of the document."

    -- Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "kkkJoe" wrote in message news:6ee7c475-3a7d-47ec-9940-c61fdeef7f34@communitybridge.codeplex.com...

    hi i am able to export the flowdocument into the word file successfully. But may i know how to add a header to the exported word document also?

    -- Change


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Friday, August 20, 2010 5:25 AM
  • i don get you. I cannot get the Sections property appear for my Flowdocument. 

     private void FlowDocToDocx(FileStream xamlFile, FlowDocument flowDoc)

            {

    flowDoc.Section .... 


    Change
    Monday, August 23, 2010 8:53 AM
  • i don get you. I cannot get the Sections property appear for my Flowdocument. 

     

     private void FlowDocToDocx(FileStream xamlFile, FlowDocument flowDoc)

            {

    flowDoc.Section .... 

    Hi Change

    A "FlowDocument" is not a Microsoft Word document. I don't know what a FlowDocument is, nor do you show us how you "export" it to a Word document. Without that information, it's not possible to give you a code sample you'll find meaningful.

    In any case, "Sections" is a property of a Microsoft.Office.Interop.Word document, not a FlowDocument. In C#, the code would be:

    wordDoc.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "the text";


    Cindy Meister, VSTO/Word MVP
    Monday, August 23, 2010 1:53 PM
    Moderator
  • hi the below is my code. The export from flowdocument to word file is succcessful. It just that i need to add in a header to the exported word file. I have added the code for oDoc.Sections. However, how do i merge the header back to the exported word document?

     

     


    Change
    • Edited by kkkJoe Monday, August 30, 2010 7:10 AM
    Wednesday, August 25, 2010 3:24 AM
  • Hi Change

    You're transforming the FlowDocument to an OpenXML file format? Then you need to pursue this question in a forum that specializes in OpenXML. I'm going to move it to the OpenXML SDK forum. They should be able to give you information on how to write Header information to a Word OpenXML document.

    FWIW you could create a document in the Word application (as an end-user) then inspect the OpenXML package, to see how Word does it.

    The Word Developer forum specializes in "Interop". And you can't use Interop and OpenXML together.


    Cindy Meister, VSTO/Word MVP
    Wednesday, August 25, 2010 7:53 AM
    Moderator
  • anyone has any idea?
    Change
    Thursday, August 26, 2010 2:31 AM