none
After copy and paste from another document, tables lose their formatting RRS feed

  • Question

  • Hi there,

    I'm copying text and tables from incoming documents into an empty (templated) Word doc, using v12 of Microsoft.Office.Interop.Word.dll. 

    After paste all looks OK except tables, which look empty - a twenty row table appears fully collapsed (a thick black line, all of the table borders with zero height), or full height with no content (can't select any text in the cell).  I think a style is being misplaced somehow??

    - I can reapply 'Normal' style to the entire table, which reveals the content, but all text formatting (e.g. bold text) is lost (cell borders are ok!) 
    - Applying Normal, then bold and underline (on a cell by cell basis) works ok but is very slow (increases render time from 30 secs to 5 minutes!)

    Is there a way I can refresh styles faster, or copy across, retaining formatting?  I copy section by section, paste section by section.

    Thansk in advance!

    Ken

     

    • Moved by Cindy Meister MVPModerator Wednesday, August 10, 2011 2:03 PM not using VSTO technology (From:Visual Studio Tools for Office)
    Wednesday, August 3, 2011 7:25 AM

Answers

  • Hi Ken

    Please show us the code involved with the "copy/paste".

    FWIW I avoid using those commands whenever possible. Usually, the Range.FormattedTExt = Range.FormattedText approach works just fine.

    I don't know if that will solve the issue in this case, because it's not clear where the problem is coming from. It sounds like the STYLE applied to the text in the table is present in both documents, but with very different style definitions...


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Ken McCormack Wednesday, August 10, 2011 3:31 AM
    Wednesday, August 3, 2011 11:55 AM
    Moderator

All replies

  • Hi Ken

    Please show us the code involved with the "copy/paste".

    FWIW I avoid using those commands whenever possible. Usually, the Range.FormattedTExt = Range.FormattedText approach works just fine.

    I don't know if that will solve the issue in this case, because it's not clear where the problem is coming from. It sounds like the STYLE applied to the text in the table is present in both documents, but with very different style definitions...


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Ken McCormack Wednesday, August 10, 2011 3:31 AM
    Wednesday, August 3, 2011 11:55 AM
    Moderator
  • Hi Cindy

    Many thanks for that tip - it solved my problem.  I had a couple of early design issues that didn't become apparent till I did some bulk transforms.  These were holding me up, as well as causing the app to run very slowly:

    - Source and destination documents were held in separate ApplicationClass processes (I presume my issues with copy / paste formatting may have been related to this)
    - Setting FormattedText between documents initially generated a TypeMismatchException - you have a post elsewhere that discusses this issue (the documents must belong to the same Word process)
    - FormattedText appears to be much faster than using clipboard operations, as preserves formatting exactly
    - Allowed me to remove historical dependencies on temporary copy+paste documents
    - Injecting an ApplicationClass dependency from the top level (allowing it to be shared throughout the entire run of 30+ documents) sped things up a lot
    - Recreating / tearing down the ApplicationClass repeatedly is slow and seems to wreak havoc with COM finalisation (causes Win 7 + VS2010 to crash!)

    Thankfully my test coverage is reasonable so I was able to revisit the core design without any issues, running 5x faster now 

    Kind Regards!

    Ken

     

     

     

     

    Wednesday, August 10, 2011 3:45 AM
  • Glad you have things up and running, Ken :-)!

    as you obviously aren't using the VSTO technology, and the issue is resolved, I'm going to move the discussion to the Word for Developers forum where it will be more on-topic and better benefit others with similar issues.


    Cindy Meister, VSTO/Word MVP
    Wednesday, August 10, 2011 2:03 PM
    Moderator