C# /VB.NET 插入、修改、删除Word批注
批注内容可以是对某段文字或内容的注释,也可以是对文段中心思想的概括提要,或者是对文章内容的评判、疑问,以及在阅读时给自己或他人起到提示作用。本篇文章中将介绍如何在C#中操作Word批注,主要包含以下要点:
- 插入Word批注
- 修改Word批注
- 删除Word批注
使用工具:Free Spire.Doc for .NET 6.3(最新社区版)
注:编辑代码前注意添加引用Sprie.Doc.dll(dll文件可在安装路径下的Bin文件夹中获取)

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[];
Paragraph paragraph = section.Paragraphs[]; //添加文本到批注
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)
'实例化一个Document类对象,并加载Word文档
Dim document As Document = New Document
document.LoadFromFile("sample.docx")
'获取第一段第一节
Dim section As Section = document.Sections()
Dim paragraph As Paragraph = section.Paragraphs()
'添加文本到批注
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
测试结果:

2.修改、删除批注
测试文档:

C#
using Spire.Doc; namespace ReplaceAndRemoveComment_Word
{
class Program
{
static void Main(string[] args)
{
//初始化Document类实例,加载带有批注的Word文档
Document document = new Document();
document.LoadFromFile("test.docx"); //修改第一个批注内容
document.Comments[].Body.Paragraphs[].Replace("This paragraph describes the origin and the purpose of WEF", "What is the WEF ?", false, false); //移除第二个批注
document.Comments.RemoveAt(); //保存并打开文档
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)
'初始化Document类实例,加载带有批注的Word文档
Dim document As Document = New Document
document.LoadFromFile("test.docx")
'修改第一个批注内容
document.Comments().Body.Paragraphs().Replace("This paragraph describes the origin and the purpose of WEF", "What is the WEF ?", false, false)
'移除第二个批注
document.Comments.RemoveAt()
'保存并打开文档
document.SaveToFile("RemoveAndReplace.docx", FileFormat.Docx)
System.Diagnostics.Process.Start("RemoveAndReplace.docx")
End Sub
End Class
End Namespace
测试结果:

以上是本次关于操作Word批注的全部内容。感谢浏览!
C# /VB.NET 插入、修改、删除Word批注的更多相关文章
- C# /VB.NET操作Word批注(一)—— 插入、修改、删除Word批注
批注内容可以是对某段文字或内容的注释,也可以是对文段中心思想的概括提要,或者是对文章内容的评判.疑问,以及在阅读时给自己或他人起到提示作用.本篇文章中将介绍如何在C#中操作Word批注,主要包含以下要 ...
- Java 添加、回复、修改(替换)、删除Word批注
批注是一种常用于对特定文档内容进行注解的工具或方法,起到解释说明.标记指正的作用.在本篇文章中,将介绍如何操作Word批注的方法,包括: 1. 添加批注:添加文本到批注.插入图片到批注: 2. 回复批 ...
- Hibernate 插入,修改,删除,查询语句
/* *具体操作hibernate的类 *增加,删除,修改,按ID查询,模糊查询,查询全部 **/ public class PersonOperate { //在hibernate中所有操作都是由S ...
- 图文并解Word插入修改删除批注
.插入批注 首先选择对象,比如部分文字[hd1] ,之后执行这样的操作:"插入"→"批注":插入的批注处于编辑状态,可以直接输入批注的文字即可;图解如下: .修 ...
- jdom 插入 修改 删除
创建XML文档 XML文件是一种典型的树形文件,每个文档元素都是一个document元素的子节点.而每个子元素都是一个Element对象,对象可以向下包含. 1 因此我们可以通过先创建元素再将元素添加 ...
- C#/VB.NET 操作Word批注(二)——如何插入图片、读取、回复Word批注内容
序 在前面的文章C# 如何插入.修改.删除Word批注一文中介绍了如何操作Word批注的一些方法,在本篇文章中继续介绍操作Word批注的方法.分以下三种情况来介绍: 1. 插入图片到Word批注 2. ...
- Java 读取Word批注中的文本和图片
本文将介绍读取Word批注的方法,包括读取Word批注中的文本及图片.关于操作Word批注的方法还可以参考这两篇文章:Java 添加.回复.修改.删除Word批注:Java 给Word指定字符串添加批 ...
- Java 获取Word批注所标记的文本和图片
[环境配置] 本文将通过Java程序代码来展示如何来获取Word批注所标注的文本和图片.这里使用的Word Jar包工具是Free Spire.Doc for Java,在pom.xml中按如下步骤配 ...
- Delphi ADOQuery连接数据库的查询、插入、删除、修改
http://blog.csdn.net/chinazhd/article/details/45047777 //查询记录 procedure TForm1.Button1Click(Sender: ...
随机推荐
- Android JavascriptBridge 详解(二)
原文出自:http://blog.csdn.net/sk719887916/article/details/47189607 Android开发目前现状来说,开发者大部分时间花在UI的屏幕适配上,使用 ...
- linux shell 判断文件是否存在等符号
-a file exists. -b file exists and is a block special file. -c file exists and is a character spec ...
- Android平移动画
Android平移动画 核心方法 public void startAnimation(Animation animation) 执行动画,参数可以是各种动画的对象,Animation的多态,也可以是 ...
- Android项目开发填坑记-so文件引发的攻坚战
故事的最初 我负责的项目A要求有播放在线视频的功能,当时从别人的聊天记录的一瞥中发现百度有相关的SDK,当时找到的是Baidu-T5Player-SDK-Android-1.4s,项目中Demo的so ...
- Centos7安装RocketMQ及配置测试
环境 Centos7 RocketMQ 3.2.6 安装位置 /usr/local/alibaba-rockermq 外网ip 182.254.145.66 内网ip 10.105.23.114 安装 ...
- python 多进程 logging:ConcurrentLogHandler
python 多进程 logging:ConcurrentLogHandler python的logging模块RotatingFileHandler仅仅是线程安全的,如果多进程多线程使用,推荐 Co ...
- Andriod Studio科普篇——4.关于编译的常见问题
1.android支持库未安装 编译不过,提示如下: Could not find any version that matches com.android.support:appcompat-v7: ...
- iOS中 流媒体播放和下载 韩俊强的博客
每日更新关注:http://weibo.com/hanjunqiang 新浪微博 iOS中关于流媒体的简介:介于下载本地播放与实时流媒体之间的一种播放形式,下载本地播放必须全部将文件下载完成后才能播 ...
- 简述Java内存泄露
翻译人员: 铁锚翻译时间: 2013年11月4日原文链接: The Introduction of Memory Leaks内存管理一直是Java 所鼓吹的强大优点.开发者只需要简单地创建对象,而Ja ...
- Css的学习之旅-css的选择器(2)
1.最常用的是派生选择器:eg:ul li{ color:red} 2.id选择器:eg:#id{color:red} 3.类选择器:设置标签的class = "",类似id.用点 ...