none
Pasting intp PPTX not keeping sourcing format RRS feed

  • Question

  • Hello All; 

    I'm trying to paste an excel table into a PPTX and keeping the format. It comes as a surprise that no matter what I do it does not work as expected.

    PowerPoint.PpPasteDataType.ppPasteHTML not emulating the ctrl+alt+v then selecting Paste + HTML Format

    any clue as to how to perform this action? (Paste in pptx keeping source formatting).

    Also, I have tried app.CommandBars.ExecuteMso("PasteSourceFormatting"); which works at a times only. When I iterate through multiple objects copied to the clipboard, it doesn't work as expected. 

    Please advise. 

    Here is my code:

    private void TEST2()
            {
                excelHandler = new CustomExcelHandler();
                List<string> cellList = new List<string>();
                bool lastItem = false;
                app = new PowerPoint.Application();
                PowerPoint.Presentation pptPresentation = app.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);

                try
                {

                    Excel.Worksheet worksheet = Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets[1];
                    Excel.Range selection = Globals.ThisAddIn.Application.Selection as Excel.Range;
                    cellList = excelHandler.LoopThroughList(selection);
                    Excel.Range copy_to = (Excel.Range)worksheet.get_Range(ebINCNUM.Text);
                    Excel.Range copy_to_pptx = (Excel.Range)worksheet.get_Range(ebPptxSelection.Text);

                    for (int i = 0; i < cellList.Count; i++)
                    {
                        pptPresentation.Slides.Add(pptPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutBlank);
                    }

                    string fileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Sample1.pptx";                
                    pptPresentation.SaveAs(fileName, PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation,       Microsoft.Office.Core.MsoTriState.msoTriStateMixed);
                    
                    Clipboard.Clear();

                    for (int i = 0; i < cellList.Count; i++)
                    {
                        copy_to.Value2 = cellList[i].ToString();
                        System.Threading.Thread.Sleep(500);
                        copy_to_pptx.Copy();
                        PowerPoint.Slide pptSlide = pptPresentation.Slides[i+1];

                        //app.CommandBars.ExecuteMso("PasteSourceFormatting"); //OK  just for the firstitem :( 

                        pptSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPasteHTML,
                                                    Microsoft.Office.Core.MsoTriState.msoFalse,
                                                    string.Empty, 0,
                                                    string.Empty, Microsoft.Office.Core.MsoTriState.msoFalse);
                    }                

                    }
                }
                catch (Exception ex)
                {
                    //other stuff

                }

    Tuesday, November 26, 2019 6:10 PM

All replies

  • Hi lecalixto,

    Thank you for posting here.

    Since this thread is related to VSTO, I suggest you can ask this question in VSTO forum.

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 27, 2019 9:19 AM
  • Thank you, Timon :) 
    Monday, December 2, 2019 7:39 PM