Spire.Doc如何删除Word文档中指定的注释或评论

作者:控件中国网   出处:控件中国网   2016-12-02 10:48:06   阅读:19

在传阅相关Word文档时,经常需要在Word文件里添加注释或者评论,Spire.Doc是一款Word文档处理类控件,不仅可以帮助客户在Word文件中添加注释和评论,还可以在添加了注释或者评论的文档里删除指定的评论,下面的代码讲述了如何根据评论的作者来删除相关评论,具体如下:
class Program
    {
        static void Main(string[] args)
        {
            DeleteComments("DeleteComments.docx", "Gary zhang");
        }
        public static void DeleteComments(string fileName, string authorName)
        {
            Document spireDoc = new Document();
            spireDoc.LoadFromFile(fileName);
            if (authorName == "")
            {
                spireDoc.Comments.Clear();
            }
            else
            {
                for (int i = 0; i < spireDoc.Comments.Count; i++)
                {
                    if (spireDoc.Comments[i].Format.Author == authorName)
                    {
                        spireDoc.Comments.Remove(spireDoc.Comments[i]);
                    }
                }
            }
            spireDoc.SaveToFile(fileName, FileFormat.Docx);
        }
    }
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat