Spire.Doc 教程:从C#和VB.NET的word文档中删除形状

具有形状的示例单词文档:

图片1

Step 1:初始化Document类的新实例,并从文件加载文档。

Document doc = new Document();doc.LoadFromFile("Shapes.docx",FileFormat.Docx2010);

Step 2:从文档中获取第一个部分,并从该部分获取第一个段落。

Section section = doc.Sections[0];Paragraph para = section.Paragraphs[0]

Step 3:从第一段获取形状。

ShapeObject shape = para.ChildObjects[0] as ShapeObject;

Step 4:去除形状或所有形状。

////clear all the shapes.//para.ChildObjects.Clear();

Step 5:将文档保存到文件。

doc.SaveToFile("Removeshape.docx",FileFormat.Docx2010);

从Word文档中删除一个形状后的效果截图:

图片2

完整代码:

[C#]

Document doc = new Document();doc.LoadFromFile("Shapes.docx",FileFormat.Docx2010);Section section = doc.Sections[0];Paragraph para = section.Paragraphs[0];ShapeObject shape = para.ChildObjects[0] as ShapeObject;//remove the third shape.para.ChildObjects.RemoveAt(2);////clear all the shapes.//para.ChildObjects.Clear();doc.SaveToFile("Removeshape.docx",FileFormat.Docx2010);

[VB.NET]

Dim doc As New Document()doc.LoadFromFile("Shapes.docx", FileFormat.Docx2010)Dim section As Section = doc.Sections(0)Dim para As Paragraph = section.Paragraphs(0)Dim shape As ShapeObject = TryCast(para.ChildObjects(0), ShapeObject)'remove the third shape.para.ChildObjects.RemoveAt(2)'''/clear all the shapes.'para.ChildObjects.Clear();doc.SaveToFile("Removeshape.docx", FileFormat.Docx2010)

控件

标签:文档管理图表控件控件word文档处理

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2017年7月4日
下一篇 2017年7月5日

相关推荐

发表回复

登录后才能评论