?
Solved

C# MS Word Interop - Losing Formatting when pasting

Posted on 2014-03-27
9
Medium Priority
?
1,729 Views
Last Modified: 2014-04-01
I have an application that opens a word document and copies it to a another word document.  The issue I am having is the original word document contains line drawings instead of tables with borders.  When the document is pasted those drawings move half way down the page instead of on top where its suppose to be.

//Copy
try
{
    wApp.Selection.WholeStory();
    wApp.Selection.Copy();
}
catch (Exception ex)
{
    MessageBox.Show("Error on Copy" + ex.Message);
    return -2;
}

//Paste
try
{
    masterDoc.Activate();
    masterDoc.Select();
    masterDoc.Application.Selection.NoProofing = 1; 
    masterDoc.Application.Selection.MoveEnd(ref missing, ref missing);
    masterDoc.Application.Selection.MoveRight(ref missing, ref missing, ref missing);   
    masterDoc.Application.Options.SuggestSpellingCorrections = false;
    masterDoc.Application.Options.CheckGrammarAsYouType = false;
    masterDoc.Application.Options.CheckSpellingAsYouType = false;
    masterDoc.Application.Options.CheckGrammarWithSpelling = false;
    masterDoc.Application.DisplayAlerts = 
          Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;

    wApp.Selection.Paste();
}
catch (Exception ex)
{
    MessageBox.Show("Error on Reactivate paste" + ex.Message);
    return -2;
}

Open in new window


Any Ideas?
0
Comment
Question by:CipherIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 39959365
Instead of Paste there is a PasteAndFormat - you could try using that instead.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39959368
We would need to know what mechanism is used to ensure that the shapes appear at the top of the page. Is there any chance of posting the document (redacted if necessary)?
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 39959370
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:CipherIS
ID: 39959733
Tried this

 wApp.Selection.PasteAndFormat(
               Microsoft.Office.Interop.Word.WdRecoveryType.wdFormatOriginalFormatting);

Still not working

 try
{
    masterDoc.Activate();

    masterDoc.Select();
    masterDoc.Application.Selection.NoProofing = 1;  
    masterDoc.Application.Selection.MoveEnd(ref missing, ref missing);
    masterDoc.Application.Selection.MoveRight(ref missing, ref missing, ref missing);  
    masterDoc.Application.Options.SuggestSpellingCorrections = false;
    masterDoc.Application.Options.CheckGrammarAsYouType = false;
    masterDoc.Application.Options.CheckSpellingAsYouType = false;
    masterDoc.Application.Options.CheckGrammarWithSpelling = false;
    masterDoc.Application.DisplayAlerts = 
            Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;

    //wApp.Selection.Paste();
    wApp.Selection.PasteAndFormat(
               Microsoft.Office.Interop.Word.WdRecoveryType.wdFormatOriginalFormatting);
 }

Open in new window

0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39959871
There are many factors that could be in play here, so do consider posting a document, either the one in question redacted for confidential data, or a similar one created for this purpose,
0
 
LVL 1

Author Comment

by:CipherIS
ID: 39960020
I've attache copies of the From document (Word 01) and the To document (Word 02).  I had to redact data but I think its enough to show difference.
Word01.jpg
Word02.jpg
0
 
LVL 1

Accepted Solution

by:
CipherIS earned 0 total points
ID: 39960192
Thanks for all your help.  I figured out how to fix it.  The original document was in rtf format.  So I created the new document in rtf format then performed the copy and paste.  Working now.

Thanks again
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39960406
Even with formatting marks showing, pictures of the documents would not have been enough to work out how the layout is achieved. We would have needed an actual document.
If some or all of the layout is implemented with drawing objects, then it is very likely to be somewhat delicate, as you have found out.
0
 
LVL 1

Author Closing Comment

by:CipherIS
ID: 39968814
Thanks for all your help.  I figured out how to fix it.  The original document was in rtf format.  So I created the new document in rtf format then performed the copy and paste.  Working now.

Thanks again
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question