c# - 使用word interp计算word文档中的分页符

标签 c# interop

我一直在互联网上搜索如何在Word文档中获取分页符,但没有结果。微软在这个主题上提供的帮助很少。对于使用单词互操作获取分页符数量方面的任何帮助,我将不胜感激。我用的是winform。 谢谢

最佳答案

您可以通过搜索 ^012 来计算分页符,如下所示:

            int totalPageBreaks = 0;
            Microsoft.Office.Interop.Word.Range rng;

            rng = doc.Range();
            rng.Collapse(WdCollapseDirection.wdCollapseStart);

            while (true) {
                rng.Find.ClearFormatting();
                rng.Find.Text = "^012";
                rng.Find.Forward = true;
                rng.Find.Wrap = WdFindWrap.wdFindStop;
                rng.Find.Format = false;
                rng.Find.MatchCase = false;
                rng.Find.MatchWholeWord = false;
                rng.Find.MatchWildcards = false;
                rng.Find.Execute();

                if (!rng.Find.Found)
                    break;

                // increment counter
                totalPageBreaks++;

                // do some processing here if you'd like

                // reset the range
                rng.Collapse(WdCollapseDirection.wdCollapseEnd);
            }

关于c# - 使用word interp计算word文档中的分页符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13058609/

相关文章:

c# - MongoDB C# 驱动程序 - 更新许多文档时的性能问题

c# - 在分类账中查找客户发票的账龄。不根据发票编号过账贷方

c# - 无法在 nuget 包管理器 visual studio 2015 安装 "Microsoft.AspNet.Razor 3.2.3"

c# - Linq 查询连接不起作用

c# - 如何检测 Excel 工作簿是否关闭(在 C# 中使用 Interop)?

c# - Access 等同于 C# List<T> 的 VBA

c# - 尝试插入我的数据失败

c++ - DX11 OpenGL 互操作 : can't copy buffer

c# - 将字符串从 C++ 传递到 C#

c++ - 如何链接到 C++/Cli 混合模式 dll 中的 native 类