Voici l'erreur:Copier vers Excel à partir VB.Net application provoque une erreur 0x800A03EC dans certains environnements
System.Runtime.InteropServices.COMException, Coller, Exception de HRESULT: 0x800A03EC
Toutes les machines sont Windows XP avec la même version d'Excel (2003). Certaines machines ont l'erreur, d'autres non. Nous devons encore trouver un modèle.
Voici le code:
Public Shared Sub ExportToExcel(ByVal dt As System.Data.DataTable)
Dim app As New Microsoft.Office.Interop.Excel.Application
app.Visible = False
Dim Book = app.Workbooks.Add
Try
Dim Sheet = CType(Book.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet)
With Sheet
Dim c As Long = Asc("A")
For Each dc As DataColumn In dt.Columns
.Range(Chr(CInt(c)) & "1").Value = dc.ColumnName.ToString
.Range(Chr(CInt(c)) & "1").Font.Bold = True
c += 1
Next
Sheet.Activate()
Sheet.Range("A2:A2").Select()
Sheet.Paste()
.Columns.AutoFit()
CType(app.ActiveWorkbook.Sheets(2), Microsoft.Office.Interop.Excel.Worksheet).Delete()
CType(app.ActiveWorkbook.Sheets(2), Microsoft.Office.Interop.Excel.Worksheet).Delete()
End With
app.Visible = True
app.UserControl = True
Catch ex As Exception
ExceptionManager.HandledException(ex, "Unable to Copy to Excel.", "You are SOL", , False)
Finally
Book = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(app)
app = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
End Try
End Sub