私は Class report
witch includes a methodを持っていRunExcelReporting
ます。コントロールテーブルを介して、どのワークブックを開くか、どのルーチンを実行するかを認識しています。
テストとして、コントロール テーブルのマクロの 1 つを間違って綴りました。
コンソール アプリケーションはメソッドのインスタンスを作成してreport
実行しRunExcelReporting
ますが、ユーザーがブックを保存するかどうかを確認するメッセージ ボックスを Excel が表示している時点で停止します。これは私にとって悪い中途半端な点です。何らかのエラー メッセージが表示されるか、変更を保存せずにワークブックを閉じたいと考えています。次のコードを修正するにはどうすればよいですか?
private void RunExcelReporting(int x) {
Excel.Application excelApp = null;
Excel.Workbook book = null;
try {
excelApp = new Excel.Application();
excelApp.Visible = true;
book = excelApp.Workbooks.Open((string)MyReportRow["XLfile" + x + "_Path"] + (string)MyReportRow["XLfile" + x + "_Name"]);//,null,true);
//loop through the four possible macros in each book
for (int j = 1; j <= 4; j++) {
if (IsNull(MyReportRow["XLfile" + x + "_Macro" + j]) == false) {
excelApp.Run((string)MyReportRow["XLfile" + x + "_Macro" + j]);
}
}
book.Close(false, Type.Missing, Type.Missing);
}
catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
finally {
if (book != null) {
//book.Close(false, Type.Missing, Type.Missing);
book = null;
}
if (excelApp != null) {
excelApp.Application.Quit();
excelApp.Quit();
excelApp = null;
}
}
}