我一直在互联网上搜索如何在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/