简体   繁体   English

如何获取DocVariable的变量名?

[英]How to get the variable name of DocVariable?

I have a word document that is filled with DocVariables. 我有一个充满DocVariables的Word文档。 What I am having trouble with is that I can't retrieve their names. 我遇到的麻烦是我无法检索他们的名字。 What works for me now is this; 现在对我有用的是这个。

foreach(Field ff in aDoc.Fields)
{
    string txt = ff.Code.Text;
    //parse...
    //it returns {DOCVARIABLE PageCount \* MERGEFORMAT } but what I want is just PageCount.
}

I tried this; 我试过了

foreach (Field ff in aDoc.Fields)
{
    if (ff.Type == WdFieldType.wdFieldDocVariable)
    {
        ff.Select();
        string s = ff.Result.Text;
    }
}

but it returns null. 但它返回null。 Can you please help me with this problem or is this what it should be like? 您能帮我解决这个问题吗?或者应该是这样?

如果您知道了,如您所说的字符串{DOCVARIABLE PageCount \\* MERGEFORMAT } ,则可以执行以下操作:

string str = txt.substring(1, txt.IndexOf(" "));

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

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