批注内容可以是对某段文字或内容的注释,也可以是对文段中心思想的概括提要,或者是对文章内容的评判、疑问,以及在阅读时给自己或他人起到提示作用。本篇文章中将介绍如何在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批注的更多相关文章

  1. 图文并解Word插入修改删除批注

    .插入批注 首先选择对象,比如部分文字[hd1] ,之后执行这样的操作:"插入"→"批注":插入的批注处于编辑状态,可以直接输入批注的文字即可;图解如下: .修 ...

  2. Hibernate 插入,修改,删除,查询语句

    /* *具体操作hibernate的类 *增加,删除,修改,按ID查询,模糊查询,查询全部 **/ public class PersonOperate { //在hibernate中所有操作都是由S ...

  3. java操作MySQL数据库(插入、删除、修改、查询、获取所有行数)

    插播一段广告哈:我之前共享了两个自己写的小应用,见这篇博客百度地图开发的两个应用源码共享(Android版),没 想到有人找我来做毕设了,年前交付,时间不是很紧,大概了解了下就接下了,主要用到的就是和 ...

  4. javasript 的DOM 节点操作:创建,插入,删除,复制以及查找节点

    DOM 含义: DOM 是文档对象模型(Document Object Model) 是一种基于浏览器编程的一套API 接口,我W3C 出台推荐的标准.其赋予了JS 操作节点的能力,当网页被加载时,浏 ...

  5. js的DOM节点操作:创建 ,插入,删除,复制,查找节点

    DOM含义:DOM是文档对象模型(Document Object Model,是基于浏览器编程的一套API接口,是W3C出台的推荐标准.其赋予了JS操作节点的能力.当网页被加载时,浏览器就会创建页面的 ...

  6. Java代码操作properties文件(读取,新增/修改,删除)

    项目中需要用到操作properties文件中的数据,记录一下 package com.bonc.savepic.save; import java.io.FileNotFoundException; ...

  7. jdom 插入 修改 删除

    创建XML文档 XML文件是一种典型的树形文件,每个文档元素都是一个document元素的子节点.而每个子元素都是一个Element对象,对象可以向下包含. 1 因此我们可以通过先创建元素再将元素添加 ...

  8. Java 添加、回复、修改(替换)、删除Word批注

    批注是一种常用于对特定文档内容进行注解的工具或方法,起到解释说明.标记指正的作用.在本篇文章中,将介绍如何操作Word批注的方法,包括: 1. 添加批注:添加文本到批注.插入图片到批注: 2. 回复批 ...

  9. [改善Java代码]频繁插入和删除时使用LinkedList

    一.分析 前面有文章分析了列表的表里方式,也就是“读”的操作.本文将介绍表的“写”操作:即插入.删除.修改动作. 二.场景 1.插入元素 列表中我们使用最多的是ArrayList,下面看看他的插入(a ...

  10. C#/VB.NET 操作Word批注(二)——如何插入图片、读取、回复Word批注内容

    序 在前面的文章C# 如何插入.修改.删除Word批注一文中介绍了如何操作Word批注的一些方法,在本篇文章中继续介绍操作Word批注的方法.分以下三种情况来介绍: 1. 插入图片到Word批注 2. ...

随机推荐

  1. mysql的必知技巧

    1.使用联合索引可以大大减少查询数据,联合索引的顺序尽量为查询的顺序

  2. 如何实现文件上传 - JavaWeb

    直接上代码 ( idea 开发,SpringBoot 框架 ): 首先是Controller的写法: package com.xxx.Controller; import com.xxx.Tools. ...

  3. Windows下搭建Redis集群

    Redis集群: 如果部署到多台电脑,就跟普通的集群一样:因为Redis是单线程处理的,多核CPU也只能使用一个核, 所以部署在同一台电脑上,通过运行多个Redis实例组成集群,然后能提高CPU的利用 ...

  4. svn错误:更新源码出现校验和不匹配问题

    svn 的文本校验和不匹配: 最近在更新自动化源代码的时候出现了一个错误:svn: Checksum mismatch while updating.... 查了下google,原来是在更新源码出现校 ...

  5. NeuChar 平台使用及开发教程(三):使用 NeuChar 的菜单服务

    上一篇<NeuChar 平台使用及开发教程(二):设置平台账号>我们已经完成了平台账号的设置,下面就马上来体验一下自定义菜单的设置吧! 进入某个 Neural Cell 的设置界面,在右侧 ...

  6. SQL 查询当前时间

    Mysql: select date_format(now(),'%Y-%m-%d'); Oracle: Oracle中如何获取系统当前时间进行语句的筛选是SQL语句的常见功能 获取系统当前时间dat ...

  7. [Swift]LeetCode246.对称数 $ Strobogrammatic Number

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  8. [Swift]LeetCode328. 奇偶链表 | Odd Even Linked List

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...

  9. [Swift]LeetCode678. 有效的括号字符串 | Valid Parenthesis String

    Given a string containing only three types of characters: '(', ')' and '*', write a function to chec ...

  10. Visual Studio 2010软件安装教程

    链接:https://pan.baidu.com/s/10FeLlKpzFcb9yUjm3ZECsg 提取码:pup1 复制这段内容后打开百度网盘手机App,操作更方便哦 1.右击软件压缩包,选择解压 ...