在我的windows form app中,我想用一张幻灯片生成一个简单的ppt文件,并将一些文本转储到其中。这个过程应该是隐藏的(不启动PowerPoint或打开现有的ppt文件/模板),直到文件保存对话框出现。但是,文件保存操作会抛出一个异常,说明没有活动的表示。有没有人能解释一下?
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;
...
PowerPoint.Application pptApp = new PowerPoint.Application();
PowerPoint.Presentations ppts = pptApp.Presentations;
PowerPoint.Presentation ppt = ppts.Add(Office.MsoTriState.msoTrue);
PowerPoint.Slides slides = ppt.Slides;
PowerPoint.Slide slide = slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank);
PowerPoint.Shapes shapes = slide.Shapes;
PowerPoint.Shape shape = shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 500, 50);
shape.TextFrame.TextRange.InsertAfter("foo");
System.Windows.Forms.SaveFileDialog fd = new System.Windows.Forms.SaveFileDialog();
if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//This line throws an exception: Invalid request. There is no active presentation.
pptApp.ActivePresentation.SaveAs(fd.FileName,PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Office.MsoTriState.msoTrue);
}谢谢,
发布于 2011-01-05 05:09:04
您应该将ppt变量另存为You ()。
https://stackoverflow.com/questions/4598396
复制相似问题