您好,登錄后才能下訂單哦!
批注內(nèi)容可以是對(duì)某段文字或內(nèi)容的注釋,也可以是對(duì)文段中心思想的概括提要,或者是對(duì)文章內(nèi)容的評(píng)判、疑問(wèn),以及在閱讀時(shí)給自己或他人起到提示作用。本篇文章中將介紹如何在C#/VB中操作Word批注,主要包含以下要點(diǎn):
C#
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace InsertComment_Word
{
class Program
{
static void Main(string[] args)
{
//實(shí)例化一個(gè)Document類對(duì)象,并加載Word文檔
Document document = new Document();
document.LoadFromFile("sample.docx");
//獲取第一段第一節(jié)
Section section = document.Sections[0];
Paragraph paragraph = section.Paragraphs[0];
//添加文本到批注
string str = "This paragraph describes the origin and the purpose of WEF";
Comment comment = paragraph.AppendComment(str);
//添加批注作者
comment.Format.Author = "E-iceblue";
//保存并打開(kāi)文檔
document.SaveToFile("Comments.docx", FileFormat.Docx2010);
System.Diagnostics.Process.Start("Comments.docx");
}
}
}
VB.NET
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Namespace InsertComment_Word
Class Program
Private Shared Sub Main(ByVal args() As String)
Dim document As Document = New Document
document.LoadFromFile("sample.docx")
Dim section As Section = document.Sections(0)
Dim paragraph As Paragraph = section.Paragraphs(0)
Dim str As String = "This paragraph describes the origin and the purpose of WEF"
Dim comment As Comment = paragraph.AppendComment(str)
comment.Format.Author = "E-iceblue"
document.SaveToFile("Comments.docx", FileFormat.Docx2010)
System.Diagnostics.Process.Start("Comments.docx")
End Sub
End Class
End Namespace
測(cè)試結(jié)果:
測(cè)試文檔:
C#
using Spire.Doc;
namespace ReplaceAndRemoveComment_Word
{
class Program
{
static void Main(string[] args)
{
//初始化Document類實(shí)例,加載帶有批注的Word文檔
Document document = new Document();
document.LoadFromFile("test.docx");
//修改第一個(gè)批注內(nèi)容
document.Comments[0].Body.Paragraphs[0].Replace("This paragraph describes the origin and the purpose of WEF", "What is the WEF ?", false, false);
//移除第二個(gè)批注
document.Comments.RemoveAt(1);
//保存并打開(kāi)文檔
document.SaveToFile("RemoveAndReplace.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("RemoveAndReplace.docx");
}
}
}
VB.NET
Imports Spire.Doc
Namespace ReplaceAndRemoveComment_Word
Class Program
Private Shared Sub Main(ByVal args() As String)
Dim document As Document = New Document
document.LoadFromFile("test.docx")
document.Comments(0).Body.Paragraphs(0).Replace("This paragraph describes the origin and the purpose of WEF", "What is the WEF ?", false, false)
document.Comments.RemoveAt(1)
document.SaveToFile("RemoveAndReplace.docx", FileFormat.Docx)
System.Diagnostics.Process.Start("RemoveAndReplace.docx")
End Sub
End Class
End Namespace
測(cè)試結(jié)果:
以上是本次關(guān)于C#、VB.NET操作word批注的全部?jī)?nèi)容,感謝閱讀!
歡迎轉(zhuǎn)載,轉(zhuǎn)載請(qǐng)注明出處。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。