当前位置:
首页 > 编程开发 > Python基础教程 >
-
C# /VB.NET操作Word批注(一)—— 插入、修改、删除Word批注
批注内容可以是对某段文字或内容的注释,也可以是对文段中心思想的概括提要,或者是对文章内容的评判、疑问,以及在阅读时给自己或他人起到提示作用。本篇文章中将介绍如何在C#中操作Word批注,主要包含以下要点:
- 插入Word批注
- 修改Word批注
- 删除Word批注
使用工具:Free Spire.Doc for .NET 6.3 https://www.cnblogs.com/Yesi/p/8779294.html(最新社区版)
注:编辑代码前注意添加引用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[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) '实例化一个Document类对象,并加载Word文档 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
测试结果:
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[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) '初始化Document类实例,加载带有批注的Word文档 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
测试结果:
以上是本次关于操作Word批注的全部内容。感谢浏览!
原文链接:https://www.cnblogs.com/Yesi/p/8779294.html
最新更新
go语言写http踩得坑
【Python】爬虫笔记-从PyMySQL到DBUtils
【Python】爬虫笔记-开源代理池haipproxy使用
Python规范:提高可读性
C语言两结构体之间的成员互换
【爬虫实战项目】Python爬取Top100电影榜单
linux(Ubuntu)安装python
anaconda peompt 、labalimg 数据标注
【Python数据分析案例】python数据分析老番
【爬虫+情感判定+Top10高频词+词云图】“
一次SQL调优 聊一聊 SQLSERVER 数据页
聊一聊 SQLSERVER 的行不能跨页
再聊一下那 SQLSERVER 行不能跨页的事
大数据概述
支线第九篇:
数据库的值获取过来转换成Json数组的方法
支线第八篇:数据类型转换
支线第七篇:又是解决报错
支线第六篇:停下脚步,理清思路
支线第五篇:配置接口
【JS】原始类型是值类型吗?存储在栈上
C# List<T> 转 DataTable
C# List<T> 转 DataTable
C# List<T> 转 DataTable 方法修改版
使用插件式开发称重仪表驱动,RS232串口
实现简单的csv文件上传和bootstrap表格的下
第一百一十七篇: JavaScript 工厂模式和原型
第一百一十六篇: JavaScript理解对象
第一百一十五篇: JS集合引用类型Map
第一百一十四篇: JS数组Array(三)数组常