Microsoft.Office.Interop.Excel.Workbooks.Open() メソッドを使用して .XML ファイルを開き、Microsoft.Office.Interop.Excel.Workbook.ExportAsFixedFormat()メソッドを使用して開いたファイルを公開 (保存) しています。 .PDF ファイルとしての .XML ファイル。
現在、開発環境と運用前環境ではすべてが正常に機能していますが、運用サーバーでは、Microsoft.Office.Interop.Excel.Workbooks.Open()の呼び出しが行われると、メソッドの実行が停止されるか、実行されないようです。 (ログファイルやイベントビューアーになくても、私が知ることができる例外やエラーはありません..)そして最終的には明らかにどこにも保存された.PDFファイルはありません。
これが私のコードです:
using ExcelApp = Microsoft.Office.Interop.Excel;
public static void ToPdf()
{
// Declare the Excel Application object and set it in null state
ExcelApp.Application activeExcel = null;
// Declare the Workbook to be used within the Excel Application object
ExcelApp.Workbook openWorkBook = null;
// Used for passing parameter for the attribute of opening the .XML file
object tMiss = Type.Missing;
// .XML file location
string xmlPathName = "C:/Windows/Temp/XmlFile.xml";
try
{
// Instanitating the Excel.Application to a new valid Instance object
activeExcel = new ExcelApp.Application();
// Open Excel as Hiden
activeExcel.Visible = false;
// Open Excel w/o alerts
activeExcel.DisplayAlerts = false;
//
// Log this line
//
LogTxt.LogCreator("Set Excel GUI to be open Hiden with no Alerts");
// Open an Excel instance and passing the .XML file Path
openWorkBook = activeExcel.Workbooks.Open(xmlPathName, 0, false, tMiss, tMiss,
tMiss, true, tMiss, tMiss, tMiss,
true, tMiss, false, false);
//
// Log this line
//
LogTxt.LogCreator("Excel Application Opend");
// Publishing the opened workbook (.xml file) as .pdf file
openWorkBook.ExportAsFixedFormat(ExcelApp.XlFixedFormatType.xlTypePDF, pdfPathName);
//
// Log this line
//
LogTxt.LogCreator("Excel to .PDF published");
}
catch (Exception ee)
{
LogTxt.LogCreator(string.Format("Error is {0}", ee.InnerException.Message));
}
finally
{
// Flag for finding the Excel process or not
//bool foundExcel = false;
if (openWorkBook != null)
{
// Closing the workbook
openWorkBook.Close(false, tMiss, tMiss);
// here we say that this object is not going to be called anymore
Marshal.ReleaseComObject(openWorkBook);
}
if (activeExcel != null)
{
// Closing the Excel
activeExcel.Quit();
// here we say that this object is not going to be called anymore
Marshal.ReleaseComObject(activeExcel);
//
// Log this line
//
LogTxt.LogCreator("Excel Procces Closed");
}
GC.GetTotalMemory(false);
// Calling to GC go through all gen
GC.Collect();
// Stops the corrent thread untill the Finalizers empty the queue
GC.WaitForPendingFinalizers();
// Calling the GC to go through all gen
GC.Collect();
GC.GetTotalMemory(true);
}
注 - ログ ファイルに記録しているので、デプロイ後に実行されたコード行を確認できます。
また、\Users と Network Service ユーザーを Access Permissions Defaults と Launch and Activation Permissions に追加することで、コンポーネント サービス管理の [COM セキュリティ] タブで COM コンポーネントを実行する権限があることを確認しました。
ここで
説明したように。
私が求めているのは、Open() メソッドの何が問題なのかを理解するためのアイデアがあれば、ということです。