none
Formating lost while pasting content in PowerPoint RRS feed

  • Question

  • I have html content saved in SQL database, I want to insert this html content in PowerPoint presentation, so I copy the html content to clipboard, and then try to paste it in Powerpoint. It works fine for normal text with bullets, bold, italics. But with tables when I paste, the formatting is lost and it copies it as normal text.

    I put a break point before pasting it through code, and tried to manually paste the content (cltr+v) , then it works fine, the table gets pasted as it should be.

    I am using Office 2010 and VSTO.

     

    Tuesday, June 21, 2011 1:22 PM

Answers

  • Hi Navin,

    Thanks for posting your project on SkyDrive. I downloaded it and replaced the strings to my presentation template and my .html file and reproduced your problem. The problem is documented as a known bug.

    I commented out the code that loaded the existing presentation, and uncommented the code that initiates a new presentation and adds a single slide. (Incidentally, you assign the new presentation to oPres, but your code then tries to add a new slide to pptPres – you can replace that variable with ‘oPres’). The new presentation, new slide works as you said.

    Suggestion: catch the error when you paste to a slide in an existing presentation, then load a new template that matches the template of your presentation (so the slide looks like it belongs to your existing presentation) paste the html into the new slide, then copy that slide, and paste it into your existing presentation. Close the new presentation without saving it.

    Please let us know if this works for you.

    Regards,
    Chris Jensen
    Senior Technical Support Lead

    Wednesday, June 29, 2011 8:24 PM
    Moderator
  • Hi Chris,

    The solution you gave worked. This is what I did.

    Created a new presentation, applied the template to it. Then copied the slides to this newly created presentation from the original one. Then applied my automation code to this presentation using VSTO. It worked fine.

    Thanks Chris for your help.

    Regards,

    Navin Agarwal

    • Marked as answer by navin agarwal Tuesday, July 19, 2011 6:09 AM
    Tuesday, July 19, 2011 6:09 AM

All replies

  • Hi Navin agarwal,

    Could you tell us what is the type of filed that you store the html content into the SQL database?

    And it will be appreciate that if you can post the code snippet or provide us the demo project on the SkyDrive: http://www.skydrive.com and share it with us.

    I will try to reproduce your scenario and give you the suggestion.

    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.


    Thursday, June 23, 2011 3:09 AM
  • I have an infopath form, with RTF field, so it stores data in XHTML form.
    When submitting, the data goes to a webservice that inserts data in SQL.
    Now, I need to insert this XHTML in PPT.
    I use http://blog.tcx.be/2005/08/copying-html-fragment-to-clipboard.html to copy html to clipboard.  I have tried both paste and pastespecial with html type, but when pasting tables the formatting is lost.
    Saturday, June 25, 2011 11:49 AM
  • For pasting the content in PowerPoint I was doing this, first I created a text box, in a particular slide, then pasted the content in that text box.

    PowerPoint.Shape tshape = sld.Shapes.AddTextbox(office.MsoTextOrientation.msoTextOrientationHorizontal, 5, 5, 500, 500);

    tshape.TextFrame.TextRange.Paste();

    Where sld refers to a slide in PPT.

    By this method the formatting was lost, and Images were not getting pasted.

    Then I tried this,

    oPres.Application.ActiveWindow.View.Paste();

    The table was pasted in the first slide with all the formatting.

    But, I cannot use ActiveWindow in my project, while creating the PPT everything has to run in background.

    I need a way by which I can paste content in slides then position it where I want to, without making the presentation visible to user while it is being created.

     

    Monday, June 27, 2011 1:40 PM
  • Hello Navin,

    Repeating Bruce Song’s request “appreciate that if you can post the code snippet or provide us the demo project on the SkyDrive: http://www.skydrive.com and share it with us.”

    Another request is for you to try to repeat the issue by building a simple 4 column, 4 row table in Excel, and copying that to the clipboard. Then try a simple version of your code to paste that table from the clipboard into your PowerPoint slide.  If it repeats the issue please share to code to demonstrate it on the SkyDrive. Please post your results from the simple test. Thanks.

    Regards,
    Chris Jensen
    Senior Technical Support Lead


    Monday, June 27, 2011 6:32 PM
    Moderator
  • I have uploaded my demo project here

    https://skydrive.live.com/redir.aspx?cid=0f8511beb2a76be7&resid=F8511BEB2A76BE7!115

    I am using the sample html content saved in check.html to, paste it in powerpoint.

    I could solve the formatting issue by using, ActiveWindow.View.Paste() , but now I am facing another issue , when I add a new presentation by using Presentations.Add , and then then paste using View.Paste() , its working fine. But when I open an existing PPT, add a blank slide to it, and then paste content using View.Paste() , I am getting an exception.

     

    Navin Agarwal 

    Wednesday, June 29, 2011 10:54 AM
  • Hi Navin,

    Thanks for posting your project on SkyDrive. I downloaded it and replaced the strings to my presentation template and my .html file and reproduced your problem. The problem is documented as a known bug.

    I commented out the code that loaded the existing presentation, and uncommented the code that initiates a new presentation and adds a single slide. (Incidentally, you assign the new presentation to oPres, but your code then tries to add a new slide to pptPres – you can replace that variable with ‘oPres’). The new presentation, new slide works as you said.

    Suggestion: catch the error when you paste to a slide in an existing presentation, then load a new template that matches the template of your presentation (so the slide looks like it belongs to your existing presentation) paste the html into the new slide, then copy that slide, and paste it into your existing presentation. Close the new presentation without saving it.

    Please let us know if this works for you.

    Regards,
    Chris Jensen
    Senior Technical Support Lead

    Wednesday, June 29, 2011 8:24 PM
    Moderator
  • Hi Chris,

    The solution you gave worked. This is what I did.

    Created a new presentation, applied the template to it. Then copied the slides to this newly created presentation from the original one. Then applied my automation code to this presentation using VSTO. It worked fine.

    Thanks Chris for your help.

    Regards,

    Navin Agarwal

    • Marked as answer by navin agarwal Tuesday, July 19, 2011 6:09 AM
    Tuesday, July 19, 2011 6:09 AM