【发布时间】:2020-04-20 03:23:47
【问题描述】:
我目前正在尝试替换 powerpoint smartart 对象中的一些文本。我可以获取文本,但我无法设置文本值,即使很多文档看起来很简单。
我正在使用
shp.SmartArt.AllNodes[i].TextFrame2.TextRange.Text = shapeString;
设置文本字符串,但无论我使用什么函数,我都会遇到错误
shp.SmartArt.AllNodes[i].TextFrame2.DeleteText();
返回与其他消息相同的错误消息。我可能需要让 powerpoint 可见,但由于某种原因,当我让它可见时,它会消失。 (杀毒?)
我可以用标准文本框替换 powerpoint 中的文本,因此我尝试重复 smartart 的步骤,但没有成功。
**************异常文本**************
System.Runtime.InteropServices.COMException (0x80004005):对 COM 组件的调用已返回错误 HRESULT E_FAIL。 在 Microsoft.Office.Core.TextRange2.set_Text(字符串 pbstrText) 在 *.Form1.BtnStart_Click(Object sender, EventArgs e) 中 *\Form1.cs:第 414 行 在 System.Windows.Forms.Control.OnClick(EventArgs e) 在 System.Windows.Forms.Button.OnClick(EventArgs e) 在 System.Windows.Forms.Button.PerformClick() 在 System.Windows.Forms.Form.ProcessDialogKey(键 keyData) 在 System.Windows.Forms.Control.ProcessDialogKey(键 keyData) 在 System.Windows.Forms.Control.ProcessDialogKey(键 keyData) 在 System.Windows.Forms.Control.ProcessDialogKey(键 keyData) 在 System.Windows.Forms.Control.PreProcessMessage(消息和消息) 在 System.Windows.Forms.Control.PreProcessControlMessageInternal(控制目标,消息和消息) 在 System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG&msg)
**************加载的程序集**************
mscorlib 程序集版本:4.0.0.0 Win32 版本:4.8.4075.0 构建者:NET48REL1LAST 代码库:file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
System.Windows.Forms 程序集版本:4.0.0.0 Win32 版本:4.8.4042.0 构建者:NET48REL1LAST_C 代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_0.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
系统 程序集版本:4.0.0.0 Win32 版本:4.8.4001.0 构建者:NET48REL1LAST_C 代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c> 561934e089/System.dll
系统.绘图 程序集版本:4.0.0.0 Win32 版本:4.8.3752.0 构建者:NET48REL1 代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0> __b03f5f7f11d50a3a/System.Drawing.dll
系统.配置 程序集版本:4.0.0.0 Win32 版本:4.8.3752.0 构建者:NET48REL1 代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
System.Core 程序集版本:4.0.0.0 Win32 版本:4.8.4075.0 构建者:NET48REL1LAST 代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b> 77a5c561934e089/System.Core.dll
System.Xml 程序集版本:4.0.0.0 Win32 版本:4.8.3752.0 构建者:NET48REL1 代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b7> 7a5c561934e089/System.Xml.dll
Microsoft.CSharp 程序集版本:4.0.0.0 Win32 版本:4.8.3752.0 代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Microsoft.CSharp/v4.0_4.0.0> .0__b03f5f7f11d50a3a/Microsoft.CSharp.dll
系统.动态 程序集版本:4.0.0.0 Win32 版本:4.8.3752.0 代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Dynamic/v4.0_4.0.0.0> __b03f5f7f11d50a3a/System.Dynamic.dll
匿名托管的 DynamicMethods 程序集 程序集版本:0.0.0.0 Win32 版本:4.8.4075.0 构建者:NET48REL1LAST 代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/mscorlib/v4.0_4.0.0.0__b77a5c561934e089/mscorlib.dll
自定义编组器 程序集版本:4.0.0.0 Win32 版本:4.8.3752.0 构建者:NET48REL1 代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/CustomMarshalers/v4.0_4.0.0.0__b03f5f7f11d50a3a/CustomMarshalers.dll
Microsoft.Office.Interop.PowerPoint 程序集版本:15.0.0.0 Win32版本:15.0.4569.1507 代码库:file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.Office.Interop.PowerPoint/15.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.PowerPoint.dll
办公室 程序集版本:15.0.0.0 Win32版本:15.0.4613.1000 代码库: file:///C:/WINDOWS/assembly/GAC_MSIL/office/15.0.0.0__71e9bce111e9429c/office.dll
System.Dynamic.DynamicAssembly 程序集版本:0.0.0.0 Win32 版本:4.8.3752.0 代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Dynamic/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Dynamic.dll
不知道下一步该去哪里。
*************文档/参考*************
https://help.syncfusion.com/file-formats/presentation/smartart
//Open a PowerPoint Presentation
IPresentation pptxDoc = Presentation.Open("SampleDocument.pptx");
//Traverse through shape in the first slide.
foreach (IShape shape in pptxDoc.Slides[0].Shapes)
{
if (shape is ISmartArt)
{
//Traverse through all nodes inside SmartArt
foreach (ISmartArtNode mainNode in (shape as ISmartArt).Nodes)
{
if (mainNode.TextBody.Text == "Old Content")
//Change the node content
mainNode.TextBody.Paragraphs[0].TextParts[0].Text = "New Content";
}
}
}
//Save the Presentation.
pptxDoc.Save("SmartArt.pptx");
//Close the Presentation.
pptxDoc.Close();
【问题讨论】:
标签: c# com powerpoint office-interop