Spire.Doc 获取批注的源头+书签+内容

1.通过IceBlue进行word导出,默认开启修订,如果可行的话,试一下修订模式不让用户关闭
  云端默认开启修订模式后,下载前设置文档只开启批注和和修订权限,或者在生成的时候设置限定
  参考API:https://www.e-iceblue.cn/security/protect-word-document.html
2.用户在拿到word文件后,再次上传时,精准读取表格的内容和数据库的映射关系
  使用书签生成表格,然后再获取书签中的表格信息。
  标签相关操作API:https://www.e-iceblue.cn/bookmark/add-replace-and-remove-word-bookmark.html
  操作表格API:https://www.e-iceblue.cn/table/working-with-rows-and-columns-of-word-table.html
3、需要知道用户对哪个Activety的书签加了批注,见如下代码:

 书签ID是CUS_TEST,内容是:123456789,其中345做了批注,程序运行效果

 实现代码:

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建实例,加载文档
            Document doc = new Document();
            doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\合同模板.docx");

            //获取第一个批注
            Comment comment = doc.Comments[0];
            //批注的源
            Paragraph para = comment.OwnerParagraph;
            //源的位置
            CommentMark start = comment.CommentMarkStart;
            CommentMark end = comment.CommentMarkEnd;

            //获取开始标记和结束标记在段落中的索引
            int indexOfStart = para.ChildObjects.IndexOf(start);
            int indexOfEnd = para.ChildObjects.IndexOf(end);

            //获取标记的书签
            BookmarkStart bk = (BookmarkStart)para.ChildObjects[0];
            Console.WriteLine("批注源头的书签:"+ bk.Name);
            //BookmarkEnd bk1 = (BookmarkEnd)para.ChildObjects[10];
            //根据索引获取批注的开始标记和结束标记之间的文字
            for (int i = indexOfStart + 1; i < indexOfEnd; i++)
            {
                TextRange range = (TextRange)para.ChildObjects[i];
                Console.WriteLine("批注的文字:"+range.Text);
            }

            //标记的内容
            Console.WriteLine("批注的内容:" + comment.Body.Paragraphs[0].Text);
            Console.WriteLine("批注的整段文字:");
            //源头的文本
            foreach (Paragraph p in comment.OwnerParagraph.OwnerTextBody.Paragraphs)
            {
                Console.WriteLine(p.Text);
            }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值