C#从Word文档中检索FormFields并插入到文本文件中

use*_*110 1 c# field ms-word

我试图弄清楚如何遍历文档并拉出所有表单字段并将它们插入到新的文本文件中.我正在努力寻找我将需要的功能的例子,我没有提出很多信息.也许我不是在搜索.这是我到目前为止所写的内容.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;
using System.IO;

namespace purform
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {

            // create instance of Word 
            Microsoft.Office.Interop.Word.ApplicationClass oWordApp = new Microsoft.Office.Interop.Word.ApplicationClass();

            // create instance of Word document 
            Microsoft.Office.Interop.Word.Document oWordDoc = new Document();

            object missing = System.Reflection.Missing.Value;
            try
            {
                //declare objects
                object fileName = @"C:\\path\\to\\file.doc";
                object readOnly = false;
                object isVisible = true;

                //open word doc
                oWordDoc = oWordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref readOnly,
                ref missing, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing, ref missing);

                oWordDoc.Activate();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to locate and activate document file");
            }

            object oFormFields = fieldArray[i, 0];
            oWordDoc.FormFields.get_Item(ref oFormFields).Range = 


           System.IO.File.WriteAllText(@"\\path\\to\\file.txt", fieldArray[]);



        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能获得合并域?

Ste*_*eve 6

我过去曾使用过这样的代码.
另请注意,FormFields不是合并域

    foreach(Field wdField in workDoc.Fields)
    {
        if (wdField.Type == WdFieldType.wdFieldMergeField)
        {
            wdField.Select();
            string fieldText = wdField.Result.Text;
        }
    }
Run Code Online (Sandbox Code Playgroud)