none
Paste Excel Range in Powerpoint keeping source formatting doesn't work using C# Interop RRS feed

  • Question

  • I'm trying to copy an excel table into a Powepoint, using c# interop. I would like to keep the source formatting. I've read a lot of issue (All for VBA) and finally i've tried these three options

    • ((Microsoft.Office.Interop.PowerPoint.Application)((Microsoft.Office.Interop.PowerPoint.Shape)selection).Application).CommandBars.ExecuteMso("PasteSourceFormatting");

    • ((Microsoft.Office.Interop.PowerPoint.Application)((Microsoft.Office.Interop.PowerPoint.Shape)selection).Application).CommandBars.ExecuteMso("PasteExcelTableSourceFormatting");

    • ((Microsoft.Office.Interop.PowerPoint.Application)((Microsoft.Office.Interop.PowerPoint.Shape)selection).Application).ActiveWindow.View.PasteSpecial();
    ((Microsoft.Office.Interop.PowerPoint.Application)((Microsoft.Office.Interop.PowerPoint.Shape)selection).Application).ActiveWindow.View.PasteSpecial(PpPasteDataType.ppPasteHTML);

    But all three solution do not work and kept the formatting of the Presentation.

    Did i miss somethin? Any Idea?


    • Edited by M4TT3 Friday, July 1, 2016 8:13 AM
    Friday, July 1, 2016 7:59 AM

Answers

  • Hi M4TT3,

    >> My software first create a shape (a table with only 1 row) then take the excel range and copy it in the shape

    Do you mean you copy one row Rnage from Excel to Table shape in PowerPoint? If so, I am afraid we could not achieve this with keeping format. It seems PasteSourceFormatting only supports for a table Range instead of a cell. I have tried with both code and manually, it did not work either.

    For a workaround, I would suggest you copy Table instead of cell. Or, I would suggest you try to reformat the row in PowerPoint by check the format in Excel.

    If this is a new feature you want to include in the future, I would suggest you submit a feedback in the link below:

    https://powerpoint.uservoice.com/

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, July 5, 2016 5:19 AM

All replies

  • Hi M4TT3,

    What is your Powerpoint version and Excel version? Could you share us a screen shot about your Excel Range and the output result in PPT. I made a test with Office 2013, the below code works correctly, and the table is kept source formatting.

    pptApp.CommandBars.ExecuteMso("PasteSourceFormatting");

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, July 4, 2016 2:57 AM
  • I use Office 2013. 

    This command don't work for me. It copy only one cell. 

    pptApp.CommandBars.ExecuteMso("PasteSourceFormatting");

    My software first create a shape (a table with only 1 row) then take the excel range and copy it in the shape. The problem should be here? the shape created inherit the presentation formatting. 

    Monday, July 4, 2016 8:31 AM
  • Hi M4TT3,

    >> My software first create a shape (a table with only 1 row) then take the excel range and copy it in the shape

    Do you mean you copy one row Rnage from Excel to Table shape in PowerPoint? If so, I am afraid we could not achieve this with keeping format. It seems PasteSourceFormatting only supports for a table Range instead of a cell. I have tried with both code and manually, it did not work either.

    For a workaround, I would suggest you copy Table instead of cell. Or, I would suggest you try to reformat the row in PowerPoint by check the format in Excel.

    If this is a new feature you want to include in the future, I would suggest you submit a feedback in the link below:

    https://powerpoint.uservoice.com/

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, July 5, 2016 5:19 AM
  • Hi Edward,

    No, i create a table shape with one row, then i copy into it the entire excel range. 

    Thanks. 

    Wednesday, July 6, 2016 10:11 AM
  • Hi M4TT3,

    Could you achieve this manually? As my understanding, Office Object Model is used to automate the function which Office is supported. If you could not achieve this with manually steps, it could not achieve with Office Object Model.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, July 7, 2016 6:16 AM
  • For the last one, why not try to use ppPasteOLEObject? In this way, we can definitely keep the source formatting, and you dont need to create a new powerpoint shape to put Excel range.

    However, if you want to keep the table, you cannot keep the same formatting totally. Obviously, in powerpoint, there is not much functionalities for data as well as Excel.  E.g. Filter button

    Tuesday, July 12, 2016 3:22 PM
    Moderator