.NET实现ms-Word中字数统计

今天,研究了一下C#对Word字数的统计:

    先添加引用;

    引入命名空间using Word = Microsoft.Office.Interop.Word;

   wordDoc为Word Document的对象

    Microsoft.Office.Interop.Word.Range docRanger = wordDoc.Content;
        //页数
        Pages = docRanger.ComputeStatistics(Word.WdStatistic.wdStatisticPages);
        //字数
        Words = docRanger.ComputeStatistics(Word.WdStatistic.wdStatisticWords);
        //字符数(不计空格)
        Characters = docRanger.ComputeStatistics(Word.WdStatistic.wdStatisticCharacters);
        //字符数(计空格)
        Characterswithspaces = docRanger.ComputeStatistics(Word.WdStatistic.wdStatisticCharactersWithSpaces);
        //段落数
        Paragraphs = docRanger.ComputeStatistics(Word.WdStatistic.wdStatisticParagraphs);
        //行数
        Lines = docRanger.ComputeStatistics(Word.WdStatistic.wdStatisticLines);
        //中文字符和朝鲜语单词
        Fareastcharacters = docRanger.ComputeStatistics(Word.WdStatistic.wdStatisticFarEastCharacters);
        //非中文单词
        Notchinese = Words - Fareastcharacters;
        //插图数
        int count_picture = 0;
        foreach (Word.InlineShape ish in wordDoc.InlineShapes)
        {
            if ((ish.Type == Word.WdInlineShapeType.wdInlineShapeLinkedPicture) || (ish.Type == Word.WdInlineShapeType.wdInlineShapePicture))
            {
                count_picture++;
            }
        }
        Photos = count_picture;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值