问题描述
- c#操作PowerPoint添加chart
-
最近在做一个用c#直接操作ppt的程序,通过c#处理数据后直接生成一个ppt。但是在添加图表的时候只能将图表本身加进去,数据需要人工输入图表对应的excel图表才能正确显示数据,不知道怎么才能直接就将数据加入到图表对应的excel中,这样就不在需要人工输入了下面是添加图标的代码:
private void chartButton_Click(object sender, EventArgs e)
{
string path = pptPathTextBox.Text;
OpenPPT(path);//Add a new slide int count = presentation.Slides.Count; presentation.Slides.Add(count + 1, PPT.PpSlideLayout.ppLayoutBlank); //Add a pie chart slide = presentation.Slides[count + 1]; Graph.Chart aChart = (Graph.Chart)slide.Shapes.AddOLEObject(150, 150, 480, 320,"MSGraph.Chart.8", "", MsoTriState.msoFalse, "", 0, "",MsoTriState.msoFalse).OLEFormat.Object; aChart.ChartType = Graph.XlChartType.xl3DPie; aChart.Legend.Position = Graph.XlLegendPosition.xlLegendPositionBottom; aChart.HasTitle = true; aChart.ChartTitle.Text = "It is a pie chart"; }
时间: 2024-12-29 21:24:38