none
Copy content of unsaved document RRS feed

  • Question

  • Hi,

    I need to copy the content of an unsaved word document and save it in a different document without affecting the unsaved document.

    What is the best way to do it?

    Regards,

    Himani

    Wednesday, May 11, 2011 6:20 AM

Answers

All replies

  • Hi Himani,

    If you want to use Open XML SDK. I think you can't get the text from the unsaved word documents. The sdk can only process the saved document, then we can get the text from it. Why not save the document then get the text and append to another document via Open XML SDK?

    Hope this can give you the hint.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, May 13, 2011 9:09 AM
  • Thanks, Bruce. I think we can copy using doc.Content.Copy() for unsaved doc and then pasting using doc.Content.Paste() in another document. But this approach is also not foolproof as somethimes text of some headers are not copied.

    ~Himani

    Monday, May 16, 2011 5:23 AM
  • Hi Himani,

    It seems that you used the word PIA via doc.Content.Copy() method. Is that right? If so, you can refer to the document:

    http://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.document.content(VS.80).aspx which says that it can only get the main document story. So, you also need to get the header or footer and then copy to the clipboard, just as follows:

    this.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Copy()
    

    Hope this can give you the hint.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Bruce Song Friday, May 27, 2011 11:02 AM
    Tuesday, May 17, 2011 11:06 AM