私はmergefieldとbookmarkを使用してワードドキュメントを処理しています。アプリケーションはデバッグモードではうまく動作しますが、リリースモードではエラーが発生します。その他の詳細が必要な場合は、私に知らせてください。ソースコードは以下のとおりです。リソースがすでに使用されているためにC#アプリケーションのeerorがスローされた.netを使用している。
> Blockquote
object nothing = System.Reflection.Missing.Value;
object filename = "E:\\Templatenew.doc";
object destination = "E:\\new.doc";
object nottrue = false;
object oPrintdate = "printdate";
object oClientname = "clientname";
object oClientsname = "clientsname";
object oAsondate = "asondate";
object oAmount = "amount";
myWordApp.Visible = false;
myWordDoc = myWordApp.Documents.Add(ref filename, ref nothing, ref nothing, ref nothing);
myWordDoc.Activate();
myWordDoc.Bookmarks.get_Item(ref oPrintdate).Range.Text = System.DateTime.Now.ToShortDateString();
myWordDoc.Bookmarks.get_Item(ref oClientname).Range.Text = objproperty.firstname +"" + objproperty.lastname;
myWordDoc.Bookmarks.get_Item(ref oAmount).Range.Text = "10000";
myWordDoc.SaveAs(ref destination, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing,
ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing);
myWordDoc.Close(ref destination, ref filename, ref nothing);
Response.ContentType = "application/msword";
myWordApp.Application.Quit(ref nottrue, ref nothing, ref nothing);
Response.WriteFile("E:\\new.doc");
Response.End();
> Blockquote
サーバー上でWordを自動化しないでください。これは、これを含む重大な問題をもたらすでしょう。 – SLaks
正確なエラーメッセージとは何ですか、そしてそれはどの行からスローされますか? – Keith
new.docがすでに別のプロセスによって開かれている可能性はありますか? winword.exeプロセスがまだ実行中かどうか確認してください。 – Keith