有一个我发现很少有人问的问题,而且没有很好的回应。
非常简单的一段代码,在 VB.NET 中:
Imports System.Data
Imports System.IO
Imports System.Runtime.InteropServices
Dim anExcelApplicationClass As Microsoft.Office.Interop.Excel.Application
anExcelApplicationClass = New Microsoft.Office.Interop.Excel.Application
anExcelApplicationClass.Visible = False
anExcelApplicationClass.UserControl = False
anExcelApplicationClass.DisplayAlerts = False
anExcelApplicationClass.ScreenUpdating = False
Dim devWorkbooks As Workbooks
Dim devWorkbook As Workbook
Dim masterTempWorksheet As Worksheet
Dim tempWorksheet As Worksheet
devWorkbooks = anExcelApplicationClass.Workbooks
devWorkbook = devWorkbooks.Open(DevFilePath, 0, False, 5, "", "", False, XlPlatform.xlWindows, "", True, False, 0, True, False, False)
Dim tempCounter As Integer = 0
While tempCounter < 500
tempCounter = tempCounter + 1
masterTempWorksheet.Copy(Type.Missing, masterTempWorksheet)
tempWorksheet = CType(devWorkbook.Sheets(3), Worksheet)
tempWorksheet.Name = tempCounter.ToString()
End While
对我来说,在 255 次迭代后,代码失败并出现“Exception de HRESULT:0x800A03EC”的相当无用的错误。
从研究中,我看到有人说这是工作表数量的限制,但我看到其他人认为没有真正的限制,实际限制只是基于您的系统。
注意:我尝试保存并关闭,然后在经过一些迭代后重新打开工作表,如下所示:http: //support.microsoft.com/kb/210684/en-us。它没有解决问题。
有人对如何解决此问题有任何想法吗?