我正在使用c#单词2010 interop生成我的文档。
我想在表头中添加一个表格,以显示当前部分的页码和总页数,例如在使用quickpart的Word应用程序中显示的“ Y的x页”。
Cell theCell33 = headerTable.Cell(3, 3 );
[...]
theCell33.Range.Font.Size = 14f;
theCell33.Range.Font.Name = "Times New Roman";
theCell33.Range.Font.Bold = 1;
theCell33.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
范围o怎么做 ?谢谢您的帮助。
谢谢。流量。
[编辑]
我已经尝试过了:
var myCustomP = "myCustom";
var f = CurrentSection.Range.Fields.Add( CurrentSection.Range, MSWord.WdFieldType.wdFieldPage, myCustomP, true );
var f = CurrentSection.Range.Fields.Add( theCell33.Range, MSWord.WdFieldType.wdFieldPage, myCustomP, true ); // Commande non disponible //
f.Code.InsertParagraphAfter();
第一个添加字段在选择我文档的当前部分时起作用。当我尝试在表头中的表格单元格上执行相同操作时,它标记为“ Commande不负责任”(不知道EN等效项,对不起)。
Range r = theCell33.Range;
r.Collapse( MSWord.WdCollapseDirection.wdCollapseStart );
r.Fields.Add( r, MSWord.WdFieldType.wdFieldPage );
与此有关。...
我想在下面输入两个字段:f X / Y
我已经找到此网站:https://social.msdn.microsoft.com/Forums/vstudio/en-US/83d92d0d-a350-48a1-8a29-a1c4b875f861/inserting-multiple-fields-and-text-into-a-table-cell-word-2007-vbnet-2010?forum=vsto我已经尝试了一些代码,例如:
Range r = theCell33.Range; r.Collapse( MSWord.WdCollapseDirection.wdCollapseStart ); Field f = r.Fields.Add( r, MSWord.WdFieldType.wdFieldNumPages ); Range r2 = f.Result; r2.Collapse( MSWord.WdCollapseDirection.wdCollapseEnd ); r2.Text = "/"; r2.Collapse( MSWord.WdCollapseDirection.wdCollapseEnd ); r2.Fields.Add( r, MSWord.WdFieldType.wdFieldPage );
或
r.Collapse( MSWord.WdCollapseDirection.wdCollapseStart );
r.Fields.Add( r, MSWord.WdFieldType.wdFieldPage );
r.Collapse( MSWord.WdCollapseDirection.wdCollapseEnd );
r.Text = "/";
r.Collapse( MSWord.WdCollapseDirection.wdCollapseEnd );
r.Fields.Add( r, MSWord.WdFieldType.wdFieldNumPages);
但是没有正确的方法。。