简体   繁体   English

如何在MS Word页脚中向表单元格添加页码引用

[英]How to add a Page Number Reference to a table cell in a MS Word Footer

I have searched the internet trying to find an answer to this problem. 我搜索了互联网,试图找到这个问题的答案。 I am creating a program that will automatically add a footer to word documents that are in a folder. 我正在创建一个程序,该程序会自动将页脚添加到文件夹中的Word文档中。 The footer contains a table that has 2 rows and 3 columns. 页脚包含一个包含2行3列的表。 Everything is working except that the footer needs a page number reference in one of the cells. 一切正常,除了页脚在其中一个单元格中需要页码引用之外。 This is the part of my code now: 这是我现在的代码的一部分:

using Word=Microsoft.Office.Interop.Word;

Word.Table table = section.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].Range.Tables.Add(section.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].Range,2,3);
table.Range.Font.Size=8;
table.Range.Font.Name="Arial";
table.Cell(2,2).Range.Text="01 00 00 - "/*This is where the page number reference needs to be*/;

I have tried: 我努力了:

section.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].PageNumbers.Add();

and

table.Cell(2,2).Range.Fields.Add(table.Cell(2,2).Range,Word.WdFieldType.wdFieldPage);

and neither would work. 而且都不行。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Ok I created a round-a-bout way of adding the page number, so if anyone has a better answer, please feel free to add on. 好的,我创建了一种添加页码的方式,因此,如果有人有更好的答案,请随时添加。

Word.Range rng=table.Cell(2,2).Range;
rng.End=rng.End-1;
rng.Start=rng.End;
rng.Select();
app.Selection.Range.Fields.Add(app.Selection.Range,Word.WdFieldType.wdFieldPage,oMissing,oMissing);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM