彩票走势图

Word控件Spire.Doc 【文本】教程(10) ;在 word 文档中的字符或句子周围应用边框

翻译|使用教程|编辑:胡涛|2022-08-05 10:46:50.157|阅读 104 次

概述:为了强调和美化一组字符或句子,在字符或句子周围应用边框是一个不错的选择。Spire.Doc 使开发人员能够在 C# 中实现此功能。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

为了强调和美化一组字符或句子,在字符或句子周围应用边框是一个不错的选择。Spire.Doc 使开发人员能够在 C# 中实现此功能。并且有很多内置的边框样式可用,例如:Wave、Hairline、DotDash、DashSmallGap、DashLargeGap、DoubleWave、DashDotStroker、Emboss3D、Engrave3D、TwistedLines1 等等。下面的代码展示了如何使用上面提到的一些边框样式来实现字符边框: 


Spire.Doc for.NET 最新下载

 

注意:开始之前,请确保 Visual Studio 和 Spire.Doc 已正确安装。我们将使用 Spire.Doc .dll 作为参考。

第一步:加载word文档

Document doc = new Document();
Section section = doc.AddSection();

第 2 步:添加应用边框所需的字符并设置边框样式


//DashSmallGap Border
Paragraph para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
TextRange tr = para.AppendText("Spire.Doc for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DashSmallGap;
tr.CharacterFormat.Border.Color = Color.Green;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.DarkKhaki;
para.AppendBreak(BreakType.LineBreak);

//Wave Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.PDF for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.Wave;
tr.CharacterFormat.Border.Color = Color.Aqua;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.BurlyWood;
para.AppendBreak(BreakType.LineBreak);

//Emboss3D Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.XLS for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.Emboss3D;
tr.CharacterFormat.FontSize = 24;
para.AppendBreak(BreakType.LineBreak);

//DashDotStroker Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.Office for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DashDotStroker;
tr.CharacterFormat.Border.Color = Color.Olive;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.Olive;
para.AppendBreak(BreakType.LineBreak);

//DoubleWave Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.Presentation for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DoubleWave;
tr.CharacterFormat.Border.Color = Color.Blue;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.Blue;
para.AppendBreak(BreakType.LineBreak);


第 3 步:保存并启动 word 文档


doc.SaveToFile("S1.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("S1.docx");


截图效果

如何在word文档中的字符或句子周围应用边框

完整代码


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Document doc = new Document();
Section section = doc.AddSection();

//DashSmallGap Border
Paragraph para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
TextRange tr = para.AppendText("Spire.Doc for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DashSmallGap;
tr.CharacterFormat.Border.Color = Color.Green;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.DarkKhaki;
para.AppendBreak(BreakType.LineBreak);

//Wave Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.PDF for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.Wave;
tr.CharacterFormat.Border.Color = Color.Aqua;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.BurlyWood;
para.AppendBreak(BreakType.LineBreak);

//Emboss3D Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.XLS for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.Emboss3D;
tr.CharacterFormat.FontSize = 24;
para.AppendBreak(BreakType.LineBreak);

//DashDotStroker Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.Office for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DashDotStroker;
tr.CharacterFormat.Border.Color = Color.Olive;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.Olive;
para.AppendBreak(BreakType.LineBreak);

//DoubleWave Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.Presentation for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DoubleWave;
tr.CharacterFormat.Border.Color = Color.Blue;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.Blue;
para.AppendBreak(BreakType.LineBreak);

doc.SaveToFile("S1.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("S1.docx");

}
}
}



欢迎下载|体验更多E-iceblue产品

获取更多信息请咨询  ;技术交流Q群(767755948)


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP