C# /VB.NET操作Word批注(一)—— 插入、修改、删除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批注(一)—— 插入、修改、删除Word批注的更多相关文章
- 图文并解Word插入修改删除批注
.插入批注 首先选择对象,比如部分文字[hd1] ,之后执行这样的操作:"插入"→"批注":插入的批注处于编辑状态,可以直接输入批注的文字即可;图解如下: .修 ...
- Hibernate 插入,修改,删除,查询语句
/* *具体操作hibernate的类 *增加,删除,修改,按ID查询,模糊查询,查询全部 **/ public class PersonOperate { //在hibernate中所有操作都是由S ...
- java操作MySQL数据库(插入、删除、修改、查询、获取所有行数)
插播一段广告哈:我之前共享了两个自己写的小应用,见这篇博客百度地图开发的两个应用源码共享(Android版),没 想到有人找我来做毕设了,年前交付,时间不是很紧,大概了解了下就接下了,主要用到的就是和 ...
- javasript 的DOM 节点操作:创建,插入,删除,复制以及查找节点
DOM 含义: DOM 是文档对象模型(Document Object Model) 是一种基于浏览器编程的一套API 接口,我W3C 出台推荐的标准.其赋予了JS 操作节点的能力,当网页被加载时,浏 ...
- js的DOM节点操作:创建 ,插入,删除,复制,查找节点
DOM含义:DOM是文档对象模型(Document Object Model,是基于浏览器编程的一套API接口,是W3C出台的推荐标准.其赋予了JS操作节点的能力.当网页被加载时,浏览器就会创建页面的 ...
- Java代码操作properties文件(读取,新增/修改,删除)
项目中需要用到操作properties文件中的数据,记录一下 package com.bonc.savepic.save; import java.io.FileNotFoundException; ...
- jdom 插入 修改 删除
创建XML文档 XML文件是一种典型的树形文件,每个文档元素都是一个document元素的子节点.而每个子元素都是一个Element对象,对象可以向下包含. 1 因此我们可以通过先创建元素再将元素添加 ...
- Java 添加、回复、修改(替换)、删除Word批注
批注是一种常用于对特定文档内容进行注解的工具或方法,起到解释说明.标记指正的作用.在本篇文章中,将介绍如何操作Word批注的方法,包括: 1. 添加批注:添加文本到批注.插入图片到批注: 2. 回复批 ...
- [改善Java代码]频繁插入和删除时使用LinkedList
一.分析 前面有文章分析了列表的表里方式,也就是“读”的操作.本文将介绍表的“写”操作:即插入.删除.修改动作. 二.场景 1.插入元素 列表中我们使用最多的是ArrayList,下面看看他的插入(a ...
- C#/VB.NET 操作Word批注(二)——如何插入图片、读取、回复Word批注内容
序 在前面的文章C# 如何插入.修改.删除Word批注一文中介绍了如何操作Word批注的一些方法,在本篇文章中继续介绍操作Word批注的方法.分以下三种情况来介绍: 1. 插入图片到Word批注 2. ...
随机推荐
- 【原创】XAF 常见错误以及对应解决方法
1.Appearance Criteria设置错误 Exception occurs while assigning the 'DetailView, ID:xxx_DetailView' view ...
- 将python2代码转为python3
将python2代码转为python3 1.2to3在anaconda的/bin文件夹下: 2.打印帮助信息 2to3 --help 3.使用2to3 -W [要转换的python2文件目录] 4.转 ...
- 36ArcGIS API for JavaScript3.X 系列加载天地图(经纬度)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- swust oj 1051
输出利用先序遍历创建的二叉树中的指定结点的孩子结点 1000(ms) 10000(kb) 2432 / 5430 利用先序递归遍历算法创建二叉树并输出该二叉树中指定结点的儿子结点.约定二叉树结点数据为 ...
- Trie 简介
一.Trie简介 在计算机科学中,Trie,又称字典树.前缀树.单词查找树或键树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎 ...
- Hello,Thread
创建线程的三种方法,线程的生命周期,sleep,yield,join,wait 和notify,线程组,守护线程,线程的优先级 ◆ 如何创建线程 ◆ Java 中创建线程的方法有三种: 继承 Thre ...
- Spring的核心接口
ContextLoaderListener接口 Create a new ContextLoaderListenerthat will create a web application context ...
- [Swift]LeetCode120. 三角形最小路径和 | Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [Swift]LeetCode160. 相交链表 | Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- [Swift]LeetCode325. 最大子数组之和为k $ Maximum Size Subarray Sum Equals k
Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If t ...