批注內(nèi)容可以是對某段文字或內(nèi)容的注釋,也可以是對文段中心思想的概括提要,或者是對文章內(nèi)容的評判、疑問,以及在閱讀時給自己或他人起到提示作用。本篇文章中將介紹如何在C#/VB中操作Word批注,主要包含以下要點:
創(chuàng)新互聯(lián)公司于2013年創(chuàng)立,先為云夢等服務建站,云夢等地企業(yè),進行企業(yè)商務咨詢服務。為云夢企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務解決您的所有建站問題。
C#
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace InsertComment_Word
{
class Program
{
static void Main(string[] args)
{
//實例化一個Document類對象,并加載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";
//保存并打開文檔
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#
using Spire.Doc;
namespace ReplaceAndRemoveComment_Word
{
class Program
{
static void Main(string[] args)
{
//初始化Document類實例,加載帶有批注的Word文檔
Document document = new Document();
document.LoadFromFile("test.docx");
//修改第一個批注內(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);
//移除第二個批注
document.Comments.RemoveAt(1);
//保存并打開文檔
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#、VB.NET操作word批注的全部內(nèi)容,感謝閱讀!
歡迎轉(zhuǎn)載,轉(zhuǎn)載請注明出處。
分享題目:C#/VB.NET操作Word(一)——插入、修改、刪除Word批注
當前地址:http://muchs.cn/article46/jooseg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供、App開發(fā)、營銷型網(wǎng)站建設、網(wǎng)站改版、網(wǎng)站設計公司、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)