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

C#VB.NET  *** 作Word批注(二)——如何插入图片、读取、回复Word批注内容,第1张

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

在前面的文章C# 如何插入、修改、删除Word批注一文中介绍了如何 *** 作Word批注的一些方法,在本篇文章中继续介绍 *** 作Word批注的方法。分以下三种情况来介绍:

1. 插入图片到Word批注

2. 读取Word批注

3. 回复Word批注

所需工具Free Spire.Doc for .NET 6.3(社区版)Visual Studio

 PS:下载安装Free Spire.Doc 后,注意在你的程序中添加引用Spire.Doc.dll(dll文件可以在安装路径下的Bin文件夹中获取)

 

示例代码1. 插入图片到Word批注

步骤 1:添加using指令

@H_301_38@using Spire.Doc; Spire.Doc.documents; Spire.Doc.FIElds;using System.Drawing;

步骤 2:创建文档,加载测试文件

@H_301_38@document doc = new document();doc.LoadFromfile("testfile.docx");

步骤 3 :获取段落

@H_301_38@Paragraph paragraph = doc.Sections[0].Paragraphs[2];

步骤 4 :添加文本、图片到批注

@H_301_38@Comment comment = paragraph.AppendComment(探索黑科技,小米为发烧而生!");
comment.Format.Author
= administor;
DocPicture docPicture = DocPicture(doc);Image img = Image.Fromfile(mi.png);docPicture.LoadImage(img);//插入图片到批注comment.Body.AddParagraph().Childobjects.Add(docPicture);

步骤 5 :保存文件

@[email protected](result.docx,fileFormat.Docx2013);System.Diagnostics.Process.Start(");

 

测试结果:

C#全部代码:

@H_301_38@ System.Drawing;namespace InsertimgToComment_Doc{ class Program { static voID Main(string[] args) { 实例化document类,加载文档 document doc = document(); doc.LoadFromfile(); 获取需要添加批注的段落 Paragraph paragraph = doc.Sections[2]; 添加文本批注内容、批注作者 Comment comment = paragraph.AppendComment(); comment.Format.Author = ; 实例化DocPicture类,加载图片 DocPicture docPicture = DocPicture(doc); Image img = Image.Fromfile(); docPicture.LoadImage(img); 插入图片到批注 comment.Body.AddParagraph().Childobjects.Add(docPicture); 保存文件并打开文档 doc.Savetofile(); } }}VIEw Code

VB.NET代码:

@H_301_38@imports Spire.Doc Spire.Doc.documents Spire.Doc.FIElds System.Drawingnamespace InsertimgToComment_Doc Class Program Private Shared Sub Main(ByVal args As String()) Dim doc As document = New document() doc.LoadFromfile() Dim paragraph As Paragraph = doc.Sections(0).Paragraphs(Dim comment As Comment = paragraph.AppendComment() comment.Format.Author = " Dim docPicture As DocPicture = DocPicture(doc) Dim img As Image = Image.Fromfile() docPicture.LoadImage(img) comment.Body.AddParagraph().Childobjects.Add(docPicture) doc.Savetofile() End Sub End ClassEnd namespaceVIEw Code

 

2.读取Word批注

步骤 1 :添加using指令

@H_301_38@ System.Text; System.IO;using Spire.Doc.FIElds;

步骤 2 :创建实例,加载文档

@H_301_38@document doc = test.docx");

步骤 3 :将批注内容写入Txt文档

@H_301_38@实例化StringBuilder类StringBuilder SB = StringBuilder();遍历所有word批注,将批注内容写入Txt文档foreach (Comment comment in doc.Comments){ foreach (Paragraph p comment.Body.Paragraphs) { SB.Appendline(p.Text); }}file.WriteallText(CommentExtraction.txt");

C# 全部代码:

@H_301_38@ Spire.Doc.FIElds; ExtractComments{ 创建实例,加载文档 document doc = 实例化StringBuilder类 StringBuilder SB = StringBuilder(); 遍历所有word批注,将批注内容写入Txt文档 doc.Comments) { comment.Body.Paragraphs) { SB.Appendline(p.Text); } } file.WriteallText(); } }}VIEw Code

VB.NET 代码

@H_301_38@ System.Text System.IO Spire.Doc.FIElds ExtractComments Dim SB As StringBuilder = StringBuilder() For Each comment As Comment In doc.Comments Each p As Paragraph comment.Body.Paragraphs SB.Appendline(p.Text) Next Next file.WriteallText(End namespaceVIEw Code

 

3. 回复Word批注内容

步骤 1 :添加using指令 

@H_301_38@using Spire.Doc.FIElds;

步骤 2 :创建实例

@H_301_38@document doc = ");

步骤 3 :获取批注

@H_301_38@Comment comment = doc.Comments[0];

步骤 4 :回复批注

@H_301_38@Comment replyComment = Comment(doc);replyComment.Format.Author = Adam;replyComment.Body.AddParagraph().AppendText(这条批注内容请再丰富一下,内容有些单调);comment.ReplyToComment(replyComment);

步骤 5 :保存文件

@[email protected](ReplyToComment.docx");

 

测试结果:

C# 全部代码:

@H_301_38@ ReplyComment_Doc{ 实例化document类,加载文件 document doc = 获取第一个批注 Comment comment = doc.Comments[0实例化Comment类,添加批注回复作者以及回复内容 Comment replyComment = Comment(doc); replyComment.Format.Author = ; replyComment.Body.AddParagraph().AppendText(); comment.ReplyToComment(replyComment); 保存文件并打开 doc.Savetofile(); } }}VIEw Code

VB.NET 代码:

@H_301_38@ ReplyComment_Doc As Comment = doc.Comments(Dim replyComment As Comment = Comment(doc) replyComment.Format.Author = replyComment.Body.AddParagraph().AppendText() comment.ReplyToComment(replyComment) doc.Savetofile(End namespaceVIEw Code

以上为本次关于 *** 作Word批注的全部内容。

(本文完)

如需转载,请注明出处。

总结

以上是内存溢出为你收集整理的C#/VB.NET *** 作Word批注(二)——如何插入图片、读取、回复Word批注内容全部内容,希望文章能够帮你解决C#/VB.NET *** 作Word批注(二)——如何插入图片、读取、回复Word批注内容所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1213392.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存