将视觉工作室图表添加到powerpoint

时间:2012-10-09 09:29:44

标签: c# visual-studio-2010 charts powerpoint

我一直在搜索,但却无法确定如何将使用c#在visual studio 2010中创建的图表导出到excel文件中。 这是创建我的图表的代码

chart1.ChartAreas.Add("zz");
            chart1.ChartAreas["zz"].AxisX.Minimum = 0;
            chart1.ChartAreas["zz"].AxisX.Interval = 1;
            chart1.ChartAreas["zz"].AxisY.Minimum = 0;

            chart1.Series.Add("q");
            chart1.Series.Add("w");

            chart1.Series["q"].Color = Color.Aqua;
            chart1.Series["w"].Color = Color.BurlyWood;

            chart1.Series["q"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
            chart1.Series["w"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;

            for (int j = 0; j < textAdded.Count; j++)
            {
                chart1.Series["q"].Points.AddXY(j + 1, Convert.ToDouble(textAdded[j]));
                chart1.Series["w"].Points.AddXY(j + 1, Convert.ToDouble(textAdded2[j]));
            }  string ppt_fName = @"U:\ChartAdd.pptx";
            PowerPoint.Application myPPT = new PowerPoint.Application();
            myPPT.Visible = MsoTriState.msoTrue;
            myPPT.Presentations.Open(ppt_fName);


            PowerPoint.Slide s = myPPT.ActiveWindow.View.Slide;
            PowerPoint.Chart ctrng = null;
            //fails due to cast problem
            ctrng = (PowerPoint.Chart)chart1;

它不允许我将图表添加到powerpoint幻灯片上,并且想知道如何实现这一点

1 个答案:

答案 0 :(得分:0)

您可以将图表另存为图像,然后将图像添加到powerpoint中。