文档彩票走势图>>Spire.Doc系列教程>>Spire.Doc系列教程(22):添加形状和形状组合到 Word 文档
Spire.Doc系列教程(22):添加形状和形状组合到 Word 文档
更多资源查看:Spire.XLS工作表教程 | Spire.Doc系列教程 | Spire.PDF系列教程
Spire.Doc for .NET是一个专业的Word .NET库,设计用于帮助开发人员高效地开发创建、阅读、编写、转换和打印任何来自.NET( C#, VB.NET, ASP.NET)平台的Word文档文件的功能。
本系列教程将为大家带来Spire.Doc for .NET在使用过程中的各类实际操作,本篇文章介绍了如何将形状和形状组合添加到 Word 文档。
C# 添加形状和形状组合到 Word 文档
Spire.Doc支持添加多种形状(线条,矩形、基本形状,箭头,流程图,公式形状,星与旗帜及标注)等,同时各种单一的形状也可以组合在一起,成为一组形状组合。
添加单个形状
//创建一个Document实例 Document doc = new Document(); //添加一个section Section sec = doc.AddSection(); //添加一个paragraph Paragraph para1 = sec.AddParagraph(); //插入一个心形 ShapeObject shape1 = para1.AppendShape(50, 50, ShapeType.Heart); shape1.FillColor = Color.Red; shape1.StrokeColor = Color.Red; shape1.HorizontalPosition = 200; shape1.VerticalPosition = 20; //插入一个箭头 ShapeObject shape2 = para1.AppendShape(100, 100, ShapeType.Arrow); shape2.FillColor = Color.Purple; shape2.StrokeColor = Color.Black; shape2.LineStyle = ShapeLineStyle.Double; shape2.StrokeWeight = 3; shape2.HorizontalPosition = 200; shape2.VerticalPosition = 100; //插入一个公式符号 + ShapeObject shape3 = para1.AppendShape(50, 50, ShapeType.Plus); shape3.FillColor = Color.Red; shape3.StrokeColor = Color.Red; shape3.LineStyle = ShapeLineStyle.Single; shape3.StrokeWeight = 3; shape3.HorizontalPosition = 200; shape3.VerticalPosition = 200; //插入一颗star ShapeObject shape4 = para1.AppendShape(50, 50, ShapeType.Star); shape4.FillColor = Color.Gold; shape4.StrokeColor = Color.Gold; shape4.LineStyle = ShapeLineStyle.Single; shape4.HorizontalPosition = 200; shape4.VerticalPosition = 300; //保存文档 doc.SaveToFile("InsertShapes.docx", FileFormat.Docx2010);
效果图:
添加形状组合
//创建一个Document实例并添加section及paragraph Document doc = new Document(); Section sec = doc.AddSection(); Paragraph para = sec.AddParagraph(); //创建一个形状组合并设置大小 ShapeGroup shapegr = para.AppendShapeGroup(200, 400); //添加一个矩形到形状组合 shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Rectangle) { Width = 500, Height = 300, LineStyle = ShapeLineStyle.ThickThin, StrokeColor = System.Drawing.Color.Blue, StrokeWeight = 1.5, }); //添加一个三角形到形状组合 shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.RightTriangle) { Width = 500, Height = 300, VerticalPosition = 301, LineStyle = ShapeLineStyle.ThickThin, StrokeColor = System.Drawing.Color.Green, StrokeWeight = 1.5, }); //添加一个十字箭头到形状组合 shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.QuadArrow) { Width = 500, Height = 300, VerticalPosition = 601, LineStyle = ShapeLineStyle.ThickThin, StrokeColor = System.Drawing.Color.Blue, StrokeWeight = 1.5, }); //保存文档 doc.SaveToFile("InsertShapegroups.docx", FileFormat.Docx2010);
形状组合效果图:
*购买Spire.Doc for .NET正版授权的朋友可以点击哦~~