1

我想在我的 word 文档中使用公式 { = {PAGE} + 1 },在下面的示例中尝试过,但没有奏效

document.Fields.Add(sel.Selection.Range, Word.WdFieldType.wdFieldExpression, @"{PAGE}+1", true);
4

2 回答 2

1

这应该有帮助

_wordApplication.ActiveWindow.ActivePane.View.ShowFieldCodes = true;
try
{
    _wordApplication.Selection.InsertFormula("=1");                      
    _wordApplication.Selection.MoveLeft(WdUnits.wdCharacter, 1);
    _wordApplication.Selection.TypeText("+");
    var field =_wordApplication.ActiveDocument.Fields.Add(_wordApplication.Selection.Range,   Microsoft.Office.Interop.Word.WdFieldType.wdFieldEmpty, "PAGE", true);
    field.Update();

}           
finally
{
  _wordApplication.ActiveWindow.ActivePane.View.ShowFieldCodes = false;
}
于 2013-05-20T09:52:06.097 回答
0

最后我创造了这个:)

 Microsoft.Office.Interop.Word.Application _wordApplication = Globals.ThisAddIn.Application;

_wordApplication.ActiveWindow.ActivePane.View.ShowFieldCodes = true;
try
{
    _wordApplication.Selection.InsertFormula("");
    _wordApplication.Selection.MoveLeft(WdUnits.wdCharacter, 1);
    _wordApplication.Selection.TypeText("=");
    var field = _wordApplication.ActiveDocument.Fields.Add(_wordApplication.Selection.Range, Microsoft.Office.Interop.Word.WdFieldType.wdFieldEmpty, "PAGE", false);

    _wordApplication.Selection.MoveLeft(WdUnits.wdItem, 1);
    _wordApplication.Selection.TypeText("+1");
    field.Update();

}
finally
{
    _wordApplication.ActiveWindow.ActivePane.View.ShowFieldCodes = false;
}
于 2013-06-27T07:21:19.043 回答