C# 给Word中的字符添加强调符号(着重号)
1、在VS程序中打开“解决方案资源管理器”,鼠标右键点击“引用”,“管理NuGet包”:
2、点击“搜索”,在搜索框中输入搜索内容,点击包,安装:
3、依次点击“OK”,"我接受",等待程序安装。
4、完成安装后,编辑如下代码,添加强调符号(着重号)到指定文字:
using Spire.Doc;
using Spire.Doc.Documents;
using System.Drawing;
namespace EmphasisMark
{
class Program
{
static void Main(string[] args)
{
//创建Document对象
Document document = new Document();
//加载Word文档
document.LoadFromFile("sample.docx");
//查找指定字符串
TextSelection[] textSelections = document.FindAllString("分析报告", false, true);
//添加强调符号到字符串
foreach (TextSelection selection in textSelections)
{
selection.GetAsOneRange().CharacterFormat.EmphasisMark = Emphasis.DotBelow;
}
//保存文档
document.SaveToFile("Result.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("Result.docx");
}
}
}
5、执行以上代码,生成文档。可在文档中查看强调符号添加效果: