本文介绍通过spire.doc for .net读取word批注中的文本内容。读取批注中的图片,请参阅这篇文章。
c#
//创建实例,加载文档
document doc = new document();
doc.loadfromfile("sample.docx");
//实例化stringbuilder类
stringbuilder sb = new stringbuilder();
//遍历所有word批注,将批注内容写入txt文档
foreach (comment comment in doc.comments)
{
foreach (paragraph p in comment.body.paragraphs)
{
sb.appendline(p.text);
}
}
file.writealltext("result.txt", sb.tostring());
vb.net
'创建实例,加载文档
dim doc as document = new document
doc.loadfromfile("sample.docx")
'实例化stringbuilder类
dim sb as stringbuilder = new stringbuilder
'遍历所有word批注,将批注内容写入txt文档
for each comment as comment in doc.comments
for each p as paragraph in comment.body.paragraphs
sb.appendline(p.text)
next
next
file.writealltext("result.txt", sb.tostring)
批注读取结果: