Copy a Cell Range from Excel File to a Slide as a Formatted Table in C#

Working with Excel and Powerpoint I can copy a range from Excel and paste it into a Powerpoint slide with options of:

  • Use destination style
  • Use source formatting
  • Embed
  • Picture
  • Keep text only

Is it possible to copy a range from an Excel file to an Aspose slide and keep source formatting? In this case the pasted object is a formatted table that can be edited in the slide, rather than an image.

@kippow,

Following are some options for your task.

  1. You may directly convert Excel spreadsheet to PowerPoint via Aspose.Cells APIs, see the document for your reference.
    https://docs.aspose.com/cells/net/convert-workbook-to-different-formats/#convert-excel-workbook-to-pptx

  2. Alternatively, you may render range to image via Aspose.Cells and then insert the image into PowerPoint slide via Aspose.Slides but I guess this does not suit your needs.

  3. You may insert data range of Excel file as an OLE object and embed it into Powerpoint slide, see the document for your reference.
    https://docs.aspose.com/slides/net/creating-excel-chart-and-embedding-it-in-presentation-as-ole-object/

Thank you.

Numbers 2 and 3 both appear to produce in images in the Ppt file, which is not what I want to do.

Number one does what I want, but I would like to be able to do it for a specified range, rather than an entire workbook. Is that possible?

@kippow,

When you use option 3, it will embed Excel worksheet range as OLE object, so when you double click on the picture in Powerpoint slide, it will navigate you to original Excel workbook, where you may update or edit the cells as well.

You may copy remove unnecessary content/data and retain/keep only your desired range via Aspose.Cells before rendering/saving to PowerPoint presentation file.

Thanks, but that’s not what I want.

I want to be able to:

  • Create a presentation.
  • Add a slide.
  • Copy one or more specific ranges from one or more workbooks to the slide as a table(s) (not OLE and not image).
  • Add another slide.
  • Copy one or more specific ranges from one or more workbooks to the slide as a table(s).

In the example below I used option 1 from your email to export an entire workbook. This is what I want, tables, one at a time, not an entire workbook.

image.png (82.2 KB)

@kippow,

I am afraid, there is not better way to accomplish your task as both Aspose.Cells and Aspose.Slides have their limitations.

Maybe you could try in two steps:

  1. Render ranges from Excel workbooks to PPTX files (one range per PowerPoint presentation) via Aspose.Cells.
  2. Merge presentations to clone slides in final presentation via Aspose.Slides (see the document on merging presentations).

That sounds like something worth trying.

Clearly Aspose Cells has the ability to render workbook ranges as tables in a slide because it is done when I do workbook.Save(“SAVE.pptx”, Aspose.Cells.SaveFormat.Pptx). It would be great if the API exposed the functionality in such a way that I could build my slides in a piecemeal fashion from specific ranges within my workbook(s).

@kippow,

Currently, Aspose.Cells can render an Excel workbook to a PowerPoint presentation file. However, you need to choose an option that will give you results close to your requirements.

I am using:

asposeWorkbook.Save(Path.Combine(Path.GetDirectoryName(excelFilePath) ?? string.Empty, "GridToSlideTest.pptx"), SaveFormat.Pptx);

but I get the contents of the one worksheet broken into two tables on two slides. Is there any way to get it as one table on one slide?

image.png (33.0 KB)

@kippow,
Aspose.Slides is not intended for managing or parsing Excel sheets. On the other hand, Aspose.Cells can already export Excel workbooks to PowerPoint presentations. I think it would be great if Aspose.Cells allowed you to select ranges of cells to export and keep source formatting for tables.

I’ve moved the forum thread to the Aspose.Cells forum. My colleagues will help you further.

@kippow
If you only want to export a certain range to pptx format, you can first set the printing area and then export file to pptx. Please refer to the following code and attachment (51.0 KB).

Workbook wb = new Workbook(filePath + "sample.xlsx");
wb.Worksheets[0].PageSetup.PrintArea = "A4:D20";
PptxSaveOptions saveOptions = new PptxSaveOptions();            
wb.Save(filePath + "out.pptx", saveOptions);