文書を繰り返し処理する方法を理解し、すべてのフォームフィールドをプルして新しいテキストファイルに挿入しようとしています。私が必要とする機能の例を見つけようと努力しています。多くの情報がありません。たぶん私は正しく検索していないでしょう。これまで私が書いたことは次のとおりです。C#Word文書からFormFieldを取得してテキストファイルに挿入
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[]);
}
}
}
どのようにしてマージフィールドを取得できますか?
ヒントありがとうございます! – user1059110