none
maintain original source formatting while pasting with Range.PasteSpecial RRS feed

  • Question

  • This question is related to Office Interop.

    I'm trying to paste RTF content in word document using method Range.PasteSpecial method. I have following line of code :

    Clipboard.SetData(System.Windows.DataFormats.Rtf, text);
    initialRange.PasteSpecial(DataType: Microsoft.Office.Interop.Word.WdPasteDataType.wdPasteRTF);

    but problem with PasteSpecial is, it doesn't maintain the original formatting from the RTF source e.g. in my RTF source font of the text is Times New Roman but in resulting document after paste, font of the text is Calibri (which is the default font of word template file).

    I'm aware about the method Range.PasteAndFormat method which accepts formatting option but I'm not able to use that method due to some reason. 

    Anyway to maintain original source formatting using PasteSpecial method?


    Krunal C

    Sunday, January 26, 2020 11:27 AM

All replies

  • > I'm not able to use that method due to some reason.

    What reason?


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Monday, January 27, 2020 7:07 AM
  • I have created a sample application which describes the functionality which I want to achieve and problem I face in achieving it. 

    https://drive.google.com/open?id=1es1aBgewbJvQxmOAQF3FMhx3inu3keVy

    When I directly generate the report without using template file, it generates report properly but if I use template file then all the text comes up in scrambled manner. I want the same kind of output of report using template file as well which I get without template file. 

    Kindly run the sample application and let me know if you have additional question. 


    Krunal C

    Monday, January 27, 2020 7:22 AM
  • I have created a sample application which describes the functionality which I want to achieve and problem I face in achieving it. 

    https://drive.google.com/open?id=1es1aBgewbJvQxmOAQF3FMhx3inu3keVy

    When I directly generate the report without using template file, it generates report properly but if I use template file then all the text comes up in scrambled manner. I want the same kind of output of report using template file as well which I get without template file. 

    Kindly run the sample application and let me know if you have additional question. 


    Krunal C

    In regards to Google drive, you will do better by using a GitHub repository which can be done directly in Visual Studio. Looking at files on Google drive is a tedious process unlike GitHub repositories.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, January 27, 2020 10:37 PM
    Moderator