在 Word 中應(yīng)用強(qiáng)調(diào)標(biāo)記(C#/VB.NET)
	
Spire.Doc for .NET是一款專門對 Word 文檔進(jìn)行操作的 .NET 類庫。在于幫助開發(fā)人員無需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。下面我們將給您介紹如何在 Word 中應(yīng)用強(qiáng)調(diào)標(biāo)記。
Word 文檔中使用強(qiáng)調(diào)標(biāo)記來強(qiáng)調(diào)單詞并使它們更加引人注目。它通常是放在強(qiáng)調(diào)詞上方或下方的一個點或一個圓圈。但是,手動選擇單詞并在其上應(yīng)用強(qiáng)調(diào)標(biāo)記需要大量工作。幸運(yùn)的是,用于 .NET 的 Spire.Doc提供了一種更簡單的方法來通過代碼應(yīng)用強(qiáng)調(diào)標(biāo)記。本文將向您展示如何使用 Spire.Doc for .NET將強(qiáng)調(diào)標(biāo)記應(yīng)用于 Word 文檔中的文本。
為 .NET 安裝 Spire.Doc
首先,您需要將 Spire.Doc for.NET 包中包含的 DLL 文件添加為 .NET 項目中的引用。DLL 文件可以從此鏈接下載或通過NuGet安裝。
PM> Install-Package Spire.Doc
將強(qiáng)調(diào)標(biāo)記應(yīng)用于指定文本
詳細(xì)步驟如下:
- 創(chuàng)建一個文檔實例。
- 使用Document.LoadFromFile()方法從磁盤加載 Word 文檔。
- 使用Document.FindAllString()方法查找您需要強(qiáng)調(diào)的文本。
- 通過CharacterFormat.EmphasisMark屬性將強(qiáng)調(diào)標(biāo)記應(yīng)用于找到的文本。
- 使用Document.SaveToFile()方法將文檔保存到另一個 Word 文件。
【C?!?/span>
using System;
using Spire.Doc;
using Spire.Doc.Documents;
namespace applyemphasismark
{
class Program
{
static void Main(string[] args)
{
//Create a Document instance
Document document = new Document();
//Load the Word document from disk
document.LoadFromFile(@"D:\testp\test.docx");
//Find text you want to emphasize
TextSelection[] textSelections = document.FindAllString("Spire.Doc for .NET", false, true);
//Apply emphasis mark to the found text
foreach (TextSelection selection in textSelections)
{
selection.GetAsOneRange().CharacterFormat.EmphasisMark = Emphasis.Dot;
}
//Save the document to another Word file
string output = "ApllyEmphasisMark.docx";
document.SaveToFile(output, FileFormat.Docx);
}
}
}
【VB.NET】
using System;
using Spire.Doc;
using Spire.Doc.Documents;
namespace applyemphasismark
{
class Program
{
static void Main(string[] args)
{
//Create a Document instance
Document document = new Document();
//Load the Word document from disk
document.LoadFromFile(@"D:\testp\test.docx");
//Find text you want to emphasize
TextSelection[] textSelections = document.FindAllString("Spire.Doc for .NET", false, true);
//Apply emphasis mark to the found text
foreach (TextSelection selection in textSelections)
{
selection.GetAsOneRange().CharacterFormat.EmphasisMark = Emphasis.Dot;
}
//Save the document to another Word file
string output = "ApllyEmphasisMark.docx";
document.SaveToFile(output, FileFormat.Docx);
}
}
}
  
 
						
以上便是如何在 Word 中應(yīng)用強(qiáng)調(diào)標(biāo)記(C#/VB.NET),如果您有其他問題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群。
						
					

 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網(wǎng)安備
            50010702500608號
渝公網(wǎng)安備
            50010702500608號
             
            
 客服熱線
客服熱線