Home Excel.ListObject insert into PowerPoint.Shape in c#
Reply: 1

Excel.ListObject insert into PowerPoint.Shape in c#

Anwar Al-fathli
1#
Anwar Al-fathli Published in 2018-02-14 12:45:28Z
 PowerPoint.Shape shapeObject = slide.Shapes(0);
 Excel.ListObject listObject = reader.GetListObject(tableName);

  //code to insert the able into the powerpoint shape.

So I would like to put the ListObject, ChartObject from Excel into a Shape in powerpoint, is this possible?

this chart and many other chart will be going into the powerpoint So I know how to pick a Excel.ChartObject from excel sheet or table, but how do I put it as a chart with same content into a slide.

Cindy Meister
2#
Cindy Meister Reply to 2018-02-15 15:49:31Z

Since you post with a VBA tag, here's VBA code that inserts a Chart into PowerPoint. Note that in order to use Excel.Chart or workbook you need a reference to the Excel object model (PIAs) in your solution. Otherwise use the generic object, but then you won't have any Intellisense.

The AddOleObject method is the key for importing something from an OLE Server. Through OLEFormat you get basic information about the object; OLEFormat.Object gives you access to the object, itself. Note that as far as PowerPoint is concerned, this is a Shape object.

Edit: The lines commented out in the code below create a new object and show how to access the underlying Excel objects.

In order to bring in and link to an existing workbook you need to specify the file name (but not the OLE class!) and that it should be linked. Only the "top-most" Sheet in the Workbook will be displayed. Note that the linked object cannot be manipulated like the independent object - the actual file must be opened in Excel. The user can do this by double-clicking the object; code can do it using shp.OLEFormat.DoVerb 1.

Sub InsertExcelChart()
    Dim p As Presentation
    Dim s As Slide
    Dim shp As Shape
    Dim wb As Excel.Workbook 'Object
    Dim chart As Excel.chart 'object

    Set p = ActivePresentation
    Set s = p.Slides(1)
    Set shp = s.Shapes.AddOLEObject( _
        FileName:="C:\Users\Cindy Meister\Documents\SampleChart.xlsx", _
        Link:=msoTrue, DisplayAsIcon:=msoFalse)

    'Set shp = s.Shapes.AddOLEObject(10, 10, 600, 200, "Excel.Chart")
    'Debug.Print shp.OLEFormat.ProgID, shp.OLEFormat.Object.Name

    'Set wb = shp.OLEFormat.Object
    'Set chart = wb.Charts(1)
    'Debug.Print wb.Name
    'Debug.Print chart.ChartType
End Sub
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.320706 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO