Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何向MS Word页脚中的表格单元格添加页码引用_C#_.net_Ms Word_Openxml - Fatal编程技术网

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

C# 如何向MS Word页脚中的表格单元格添加页码引用,c#,.net,ms-word,openxml,C#,.net,Ms Word,Openxml,我在网上搜索,试图找到这个问题的答案。我正在创建一个程序,该程序将自动向文件夹中的word文档添加页脚。页脚包含一个有2行3列的表。除了页脚需要在其中一个单元格中引用页码外,所有操作都正常。 这是我现在代码的一部分: using Word=Microsoft.Office.Interop.Word; Word.Table table = section.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].Range.Tables.

我在网上搜索,试图找到这个问题的答案。我正在创建一个程序,该程序将自动向文件夹中的word文档添加页脚。页脚包含一个有2行3列的表。除了页脚需要在其中一个单元格中引用页码外,所有操作都正常。 这是我现在代码的一部分:

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*/;
我试过:

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

这两种方法都不管用


任何帮助都将不胜感激。

好的,我创建了一种循环添加页码的方法,因此如果有人有更好的答案,请随意添加

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);
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);