如何通过幻灯片将PIE图放入Power-point演示文稿中

时间:2018-06-12 09:24:22

标签: c# graph powerpoint

我有超过25个饼图,我想将它们放在一个带有不同幻灯片的电源点演示文稿中。

public PowerPoint.Application pptApplication = new PowerPoint.Application();
public PowerPoint.Slides objSlides;
public PowerPoint._Slide objSlide;
public PowerPoint.TextRange objTextRng;

void putinPResen(string item)
{
    WAIT_FORM wait3 = new WAIT_FORM();

    try
    {
        pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);
        string path = System.IO.Directory.GetCurrentDirectory();
        objSlides = pptPresentation.Slides;
        objSlide = objSlides.Add(Count, 
            PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
        objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
        objTextRng.Text = item.ToString();
        objTextRng.Font.Name = "Comic Sans MS";
        objTextRng.Font.Size = 40;
        objSlide.Shapes.AddPicture(path + "\\chart" + Count + ".png",   
            MsoTriState.msoFalse, MsoTriState.msoTrue, 150, 150, 500, 350);
        File.Delete(path + "\\chart" + Count + ".png");
    }
    catch (Exception ex)
    {
        wait3.Close();
        MessageBox.Show(ex.Message);
    } 
}

SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.Filter = "Excel files (*.pptx)|*.pptx|All files (*.*)|*.*";

if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = 
        pptPresentation.SlideMaster.CustomLayouts  
        [Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];

    pptPresentation.SaveAs(saveDialog.FileName, 
        Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, 
        MsoTriState.msoTrue);

当我执行这个程序时,我有多个功率点和一个捕获消息是整数超出范围。 2不是范围..

你能帮忙解决这个问题吗...真诚地感谢

0 个答案:

没有答案