C# 如何在Word文档中插入艺术字

C# 如何在Word文档中插入艺术字

在Word文档中添加艺术字效果可以让文档的排版更加美观。本篇文章主要介绍如何使用C#和Spire.Doc组件在Word文档中插入艺术字。


Spire.Doc支持多种形状类型,其中包括艺术字,这些类型可以在ShapeType枚举中找到。下面的示例添加了其中两种艺术字到Word文档。

详细步骤:

步骤1:新建一个Word文档。

Document doc = new Document();

步骤2:添加一个节和一个段落到文档。

Section section = doc.AddSection();
Paragraph paragraph = section.AddParagraph();

步骤3:插入形状到段落并指定形状的类型为艺术字。设置艺术字的文本,位置,填充色和描边色。

ShapeObject shape =paragraph.AppendShape(120, 30, ShapeType.TextWave);
shape.WordArt.Text = "感谢阅读";
shape.VerticalPosition = 80;
shape.HorizontalPosition = 170;           
shape.FillColor = Color.Yellow;
shape.StrokeColor = Color.SeaGreen;
 
shape = paragraph.AppendShape(120, 30, ShapeType.TextSlantUp);
shape.WordArt.Text = "欢迎回来";
shape.VerticalPosition = 150;
shape.HorizontalPosition = 170;
shape.FillColor = Color.Yellow;
shape.StrokeColor = Color.Red;

步骤4:保存文档。

doc.SaveToFile("艺术字.docx",FileFormat.Docx2013);

效果图:

 


完整代码:

using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
 
namespace WordArt
{
    class Program
    {
        static void Main(string[] args)
        {
            //新建Word文档
            Document doc = newDocument();
 
            //添加节和段落
            Section section = doc.AddSection();
            Paragraph paragraph = section.AddParagraph();
 
           //插入形状到段落并指定形状的类型为艺术字。设置艺术字的文本,位置,填充色和描边色
           ShapeObject shape =paragraph.AppendShape(120, 30, ShapeType.TextWave);
           shape.WordArt.Text = "感谢阅读";
           shape.VerticalPosition = 80;
           shape.HorizontalPosition = 170;           
           shape.FillColor = Color.Yellow;
           shape.StrokeColor = Color.SeaGreen;
 
 
           shape = paragraph.AppendShape(120, 30, ShapeType.TextSlantUp);
           shape.WordArt.Text = "欢迎回来";
           shape.VerticalPosition = 150;
           shape.HorizontalPosition = 170;
           shape.FillColor = Color.Yellow;
           shape.StrokeColor = Color.Red;
 
            //保存文档
           doc.SaveToFile("艺术字.docx", FileFormat.Docx2013);
        }
    }
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值