我目前正在實現一種方法,生成多個工作表並將其導出爲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