我目前正在实现一种方法,生成多个工作表并将其导出为PDF。为此,我在.NET 4.5.2中使用Microsoft.Office.Interop库(v14.0.0.0)。运行Office是2016.net互操作Excel ExportAsFixedFormat()异常HResult:0x800A03EC
我的代码:
Dim excel As New Application()
excel.Visible = False
excel.DisplayAlerts = False
Dim workbooks As Workbooks
workbooks = excel.Workbooks
Dim workbook As Workbook = workbooks.Add(Type.Missing)
[...]
workbook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, String.Format(<a Path>)
ReleaseComObject(workSheet)
workbook.Close()
ReleaseComObject(workbook)
excel.Quit()
ReleaseComObject(excel)
的ReleaseComObject的()看起来像这样(根据Microsoft Support):
Private Sub ReleaseComObject(objectToRelease As Object)
While System.Runtime.InteropServices.Marshal.ReleaseComObject(objectToRelease) > 0
End While
objectToRelease = Nothing
End Sub
,如果我对一个迭代运行这段代码也能正常工作但是我注意到EXCEL-Process仍在运行。
如果我试图做到这一点在批处理模式(在含义的for循环)我得到进入第二互为作用时EXCETION:
System.Runtime.InteropServices.COMException(0x800A03EC) :Ausnahme von HRESULT:0x800A03EC bei Microsoft.Office.Interop.Excel.WorkbookClass.ExportAsFixedFormat(XlFixedFormatType类型,对象文件名,对象质量,对象IncludeDocProperties,Object IgnorePrintAreas,Object From,Object To,Object OpenAfterPublish,Object FixedFormatExtClassPtr) bei Controller .CreateListing(DataTable data,Int32 year,String mandantShortName)in ...
行抛出异常:
workbook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, String.Format(<a Path>)
对于研制/测试我重新进入循环之前调试并杀死了Excel的过程,但W/O任何变化。
任何人都面临这个问题?解决方案/建议?
请看这篇文章http://stackoverflow.com/questions/15697282/excel-application-not-quitting-after-calling-quit – Codexer