• <menu id="w2i4a"></menu>
  • logo Spire.Doc系列教程

    文檔首頁(yè)>>Spire.Doc系列教程>>Spire.Doc系列教程(5):添加形狀和形狀組合到 Word 文檔

    Spire.Doc系列教程(5):添加形狀和形狀組合到 Word 文檔


    Spire.Doc 從版本6.0開(kāi)始,支持添加多種形狀(線條,矩形、基本形狀,箭頭,流程圖,公式形狀,星與旗幟及標(biāo)注)等,同時(shí)各種單一的形狀也可以組合在一起,成為一組形狀組合。本文主要介紹如何使用Spire.Doc在word中添加形狀及形狀組合。

    添加單個(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);

    效果圖:

    Spire.Doc

    添加形狀組合

    //創(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);

    形狀組合效果圖:

    Spire.Doc
    掃碼咨詢(xún)


    添加微信 立即咨詢(xún)

    電話咨詢(xún)

    客服熱線
    023-68661681

    TOP
    三级成人熟女影院,欧美午夜成人精品视频,亚洲国产成人乱色在线观看,色中色成人论坛 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();