我想产生的.xlsx电子表格导出为PDF。 我有两个问题:的Microsoft Office Excel的互操作ExportAsFixedFormat - 很慢,图像不加载
- 导出文件是两个方法非常缓慢 - 另存为()ExportAsFixedFormat()
- ExportAsFixedFormat不导出图像。
我正在与IIS ASP.NET服务器的代码。 https://support.comodo.com/index.php?/Knowledgebase/Article/View/1129/66/access-denied-exception-from-hresult-0x80070005-e_accessdenied
从这个库中的代码,而不会出现错误:https://github.com/aardvarkss/ExcelPDFExport
而且我生成EPPlus .xlsx文件
喜欢这里说的已经配置的权限。
代码:
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbooks excelWorkbooks = app.Workbooks;
Microsoft.Office.Interop.Excel.Workbook wkb = excelWorkbooks.Open(this.tempExcelFilePath);
foreach (Microsoft.Office.Interop.Excel.Worksheet sheet in wkb.Sheets)
{
sheet.SaveAs(this.tempPdfFilePath); // Saves the PDF correct AS I want But it cannot finish the task (waiting around 3 mins)
sheet.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, this.tempPdfFilePath); // Export PDF without image (image currently cannot be displayed), Also slow
}
wkb.SaveAs(this.tempPdfFilePath); // Waiting too long and cannot be finished
wkb.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, "C:\\Users\\user222\\Desktop\\Sample.pdf"); // Waiting too long and cannot be finish the task
// Closes the EXCEL.exe process in windows. If it not closes it cause errors.
wkb.Close(SaveChanges: false);
excelWorkbooks.Close();
app.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(wkb);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbooks);
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
任何想法,为什么它这么慢?以及如何解决我的问题?
的加载速度慢今天开始。在此之前,它没有加载缓慢的问题。
互操作既不旨在也不建议在服务器应用中使用。检查TaskManager是否没有孤立的EXCEL.EXE。 – Alex
在到达新的Microsoft.Office.Interop.Excel.Application();行之前进行调试时,在任务管理器中没有EXCEL.EXE进程。 – mihkov
好吧,我想它应该是Excel或源文件,因为它在今天之前工作。尝试重新安装服务器,看看它是否会有所作为。 – Alex