Pasting into 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);


                    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);

                    for (int i = 0; i < cellList.Count; i++)
                        copy_to.Value2 = cellList[i].ToString();
                        PowerPoint.Slide pptSlide = pptPresentation.Slides[i+1];

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

                                                    string.Empty, 0,
                                                    string.Empty, Microsoft.Office.Core.MsoTriState.msoFalse);

                catch (Exception ex)
                    //other stuff

    Monday, December 2, 2019 7:41 PM