简体   繁体   中英

PowerPoint change chart data source programmatically using c# COM interop

I'm making an application, that downloads data and generates PowerPoint presentation out out of it. I managed to get create a chart and access the data like this:

Microsoft.Office.Interop.PowerPoint.Shape Shape;
Microsoft.Office.Interop.Graph.Chart Ch;

Shape = Slide.Shapes.AddOLEObject(
                    Bounds.Left, Bounds.Top,
                    Bounds.Width, Bounds.Height,
                    ClassName);
Ch = (Graph.Chart) Shape.OLEFormat.Object;
Ch.Application.DataSheet.Cells[1, 2] = "some value";

But the data source is still the default 5x4 cells area. How can I change it? I searched for a while and saw things like .Set_DataSource(), but I don't have anything like that.

Apparently this generates the kind of chart used in the older versions of PowerPoint and the data area auto-grows there. I mostly tried to shrink the datatable and I already tried setting the cell values to null or "" and it didn't work, that's why I couldn't figure it out. Anyway, the solution was to clear the DataSheet:

Ch.Application.DataSheet.Rows.Clear();

(I found this by chance through browsing the intellisense.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM