我正试图在Interop的帮助下从演示文稿中删除一些形状。这是我写的代码:
var pptApp = new ApplicationInterop();
var presentation = pptApp.Presentations.Open(Paths.resavedAsPptxPresentation);
foreach (microsoft.Office.Interop.PowerPoint.Slide slide in presentation.Slides)
{
foreach (microsoft.Office.Interop.PowerPoint.Shape shape in slide.Shapes)
{
if (shape.HasTextFrame == microsoft.Office.Core.MsoTriState.msoTrue)
{
if (shape.TextFrame.HasText == microsoft.Office.Core.MsoTriState.msoTrue)
{
if (isWeiterShapeInterop(shape.TextFrame.textrange.Text))
{
shape.TextFrame.textrange.Text = "";
}
}
}
}
}
presentation.SaveAs(Path.Combine(Paths.tempDataDirectory,"tempPresentation.pptx"));
presentation.Close();
pptApp.Quit();
运行它时,我收到错误消息:System.Runtime.InteropServices.COMException (0x800A01A8): Exception from HRESULT: 0x800A01A8 at microsoft.Office.Interop.PowerPoint.Shape.get_HasTextFrame()
。
调试显示pptApp
完全出问题了。发生故障之前,pptApp.active
设置为msoFalse
。
请帮助