文檔首頁(yè)>>Spire.Doc系列教程>>Spire.Doc系列教程(22):添加形狀和形狀組合到 Word 文檔
Spire.Doc系列教程(22):添加形狀和形狀組合到 Word 文檔
更多資源查看:Spire.XLS工作表教程 | Spire.Doc系列教程 | Spire.PDF系列教程
Spire.Doc for .NET是一個(gè)專業(yè)的Word .NET庫(kù),設(shè)計(jì)用于幫助開(kāi)發(fā)人員高效地開(kāi)發(fā)創(chuàng)建、閱讀、編寫(xiě)、轉(zhuǎn)換和打印任何來(lái)自.NET( C#, VB.NET, ASP.NET)平臺(tái)的Word文檔文件的功能。
本系列教程將為大家?guī)?lái)Spire.Doc for .NET在使用過(guò)程中的各類實(shí)際操作,本篇文章介紹了如何將形狀和形狀組合添加到 Word 文檔。
C# 添加形狀和形狀組合到 Word 文檔
Spire.Doc支持添加多種形狀(線條,矩形、基本形狀,箭頭,流程圖,公式形狀,星與旗幟及標(biāo)注)等,同時(shí)各種單一的形狀也可以組合在一起,成為一組形狀組合。
添加單個(gè)形狀
//創(chuàng)建一個(gè)Document實(shí)例 Document doc = new Document(); //添加一個(gè)section Section sec = doc.AddSection(); //添加一個(gè)paragraph Paragraph para1 = sec.AddParagraph(); //插入一個(gè)心形 ShapeObject shape1 = para1.AppendShape(50, 50, ShapeType.Heart); shape1.FillColor = Color.Red; shape1.StrokeColor = Color.Red; shape1.HorizontalPosition = 200; shape1.VerticalPosition = 20; //插入一個(gè)箭頭 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; //插入一個(gè)公式符號(hào) + 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);
效果圖:
添加形狀組合
//創(chuàng)建一個(gè)Document實(shí)例并添加section及paragraph Document doc = new Document(); Section sec = doc.AddSection(); Paragraph para = sec.AddParagraph(); //創(chuàng)建一個(gè)形狀組合并設(shè)置大小 ShapeGroup shapegr = para.AppendShapeGroup(200, 400); //添加一個(gè)矩形到形狀組合 shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Rectangle) { Width = 500, Height = 300, LineStyle = ShapeLineStyle.ThickThin, StrokeColor = System.Drawing.Color.Blue, StrokeWeight = 1.5, }); //添加一個(gè)三角形到形狀組合 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, }); //添加一個(gè)十字箭頭到形狀組合 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);
形狀組合效果圖:
*購(gòu)買Spire.Doc for .NET正版授權(quán)的朋友可以點(diǎn)擊"咨詢?cè)诰€客服"哦~~