标签:
批注内容可以是对某段文字或内容的注释,也可以是对文段中心思想的归纳综合撮要,或者是对文章内容的评判、疑问,以及在阅读时给本身或他人起到提示感化。本篇文章中将介绍如安在C#/VB中操纵Word批注,,主要包罗以下要点: 1.插入Word批注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"); //获取第一段第一节 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 WordStrAndRemoveComment_Word { class Program { static void Main(string[] args) { //初始化Document类实例,加载带有批注的Word文档 Document document = new Document(); document.LoadFromFile("test.docx"); //改削第一个批注内容 document.Comments[0].Body.Paragraphs[0].WordStr("This paragraph describes the origin and the purpose of WEF", "What is the WEF ?", false, false); //移除第二个批注 document.Comments.RemoveAt(1); //生存并打开文档 document.SaveToFile("RemoveAndWordStr.docx", FileFormat.Docx); System.Diagnostics.Process.Start("RemoveAndWordStr.docx"); } } }
VB.NET
Imports Spire.Doc Namespace WordStrAndRemoveComment_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).WordStr("This paragraph describes the origin and the purpose of WEF", "What is the WEF ?", false, false) document.Comments.RemoveAt(1) document.SaveToFile("RemoveAndWordStr.docx", FileFormat.Docx) System.Diagnostics.Process.Start("RemoveAndWordStr.docx") End Sub End Class End Namespace测试功效: