我使用的是Microsoft.Office.Interop.Excel.Workbooks.Open()方法用于打开.XML文件,然后使用发布的Microsoft.Office.Interop.Excel.Workbook.ExportAsFixedFormat()方法(保存)打开.XML文件为.PDF文件。
现在,我的发展和预生产环境的一切运作良好,但我们的生产服务器是上看来,当呼吁Microsoft.Office.Interop.Excel.Workbooks.Open()是由该法的执行,然后把肉法甚至不执行。 (W / O任何异常或者说我可以知道任何错误,即使是在没有我的日志文件或在事件查看器..),并最终有保存的任何地方显然不是.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);
}
注 - 我登录到我的日志文件,所以我就可以看到部署后执行哪一行代码。
我还保证,我已经在权通过添加\用户和网络服务的用户访问权限默认值执行下组件服务管理COM安全选项卡COM组件,并启动和激活权限。
正如解释在这里 。
什么我问的是,如果你们有什么样的理解是错误的Open()方法的任何想法。