C++ ビルダー 5 アプリケーションを使用して Word を制御しようとしています。Word で作成した「.dot」モデル ファイルを開いて修正したいと考えています。「.dot」モデル ファイルには、いくつかのフィールドがあります。たとえば、、、などTitle
でLastName
、
これらのフィールドを変更してテキストを入力し、「.dot」ファイルを変更せずに「Warning.doc」などの新しい名前でファイルを保存したいと考えています。FirstName
Address
ファイルを開き、そこに含まれるフィールドの数を数えることはできますが、各フィールドを文字列に置き換える場合、OleFunction および OlePropertyGet メソッドに関する完全なドキュメントがないため、その方法がわかりません。ソースコードをこのメッセージに添付します。誰かこの問題を解決するのを手伝ってくれませんか?
try
{
my_word = Variant::CreateObject("word.application");
}
catch (...)
{
Application->MessageBox("Unable to obtain Word automation object",
"Error:",MB_OK | MB_ICONERROR);
}
my_word.OlePropertySet("Visible", (Variant)true);
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Variant this_doc;
Variant my_fields;
Variant test;
int k,field_count;
AnsiString test1;
AnsiString filename = "d:\\ProgrammaWord\\1-Avviso.dot";
my_docs = my_word.OlePropertyGet("Documents");
this_doc = my_docs.OleFunction("Open", filename);
my_fields = this_doc.OlePropertyGet("Fields");
field_count = my_fields.OlePropertyGet("Count");
for(k = 1; k <= field_count; k++)
{
test = my_fields.OleFunction("Item",(Variant)k);
test1 = test.OleFunction("Value"); //This instruction throws an exception
// "Value" is not a recognized parameter
// in this case
Memo1->Lines->Add(test1);
}
}