1
Private Sub Button18_Click(sender As System.Object, e As System.EventArgs) Handles Button18.Click
    Dim xlApp As Microsoft.Office.Interop.Excel.Application
    Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
    Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
    Dim misValue As Object = System.Reflection.Missing.Value
    Dim i As Integer
    Dim J As Integer

    xlApp = New Microsoft.Office.Interop.Excel.Application()
    xlWorkBook = xlApp.Workbooks.Add(misValue)
    xlWorkSheet = xlWorkBook.Sheets("Foglio1")

    For i = 0 To AplicacionesDataGridView.RowCount - 1
        For J = 0 To AplicacionesDataGridView.ColumnCount - 1
            For k As Integer = 1 To AplicacionesDataGridView.Columns.Count
                xlWorkSheet.Cells(1, k) = AplicacionesDataGridView.Columns(k - 1).HeaderText
                xlWorkSheet.Cells(i + 2, J + 1) = AplicacionesDataGridView(J, i).Value.ToString
            Next
        Next
    Next

    xlWorkSheet.SaveAs("D:\Inventorio\EXPORT\export.xlsx")
    xlWorkBook.Close()
    xlApp.Quit()

    releaseObject(xlApp)
    releaseObject(xlWorkBook)
    releaseObject(xlWorkSheet)

    Dim res As MsgBoxResult
    res = MsgBox("Proceso Completo, podrias abrir el archivo?", MsgBoxStyle.YesNo)
    If (res = MsgBoxResult.Yes) Then
        Process.Start("D:\Inventorio\EXPORT\export.xlsx")
    End If
End Sub
Private Sub releaseObject(ByVal obj As Object)
    Try
        System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
        obj = Nothing
    Catch ex As Exception
        obj = Nothing
    Finally
        GC.Collect()

    End Try

End Sub

End Class

1
  • System.Runtime.InteropServices.COMException: 'El índice no es válido. (Excepción de HRESULT: 0x8002000B (DISP_E_BADINDEX))' Commented el 4 abr. 2019 a las 2:52

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.