Tratando de exportar a Excel desde ListView en Visual Basic me puse a indagar la manera pero la mayoría de los foros solo escriben exportar desde DataGrid . Les dejo los pasos para realizar un exportación EXITOSA desde ListView…!!
Imports Microsoft.Office.Interop
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Try Dim xla As New Microsoft.Office.Interop.Excel.Application() xla.Visible = True Dim wb As Microsoft.Office.Interop.Excel.Workbook = xla.Workbooks.Add(Microsoft.Office.Interop.Excel.XlSheetType.xlWorksheet) Dim ws As Microsoft.Office.Interop.Excel.Worksheet = DirectCast(xla.ActiveSheet, Microsoft.Office.Interop.Excel.Worksheet) Dim i As Integer = 1 Dim j As Integer = 1 Dim jj As Integer = ListView1.Columns.Count For rr = 0 To ListView1.Columns.Count - 1 ws.Cells(i, j) = ListView1.Columns(rr).Text j = j + 1 Next i = 2 j = 1 For Each comp As ListViewItem In ListView1.Items ws.Cells(i, j) = comp.Text.ToString() For Each drv As ListViewItem.ListViewSubItem In comp.SubItems ws.Cells(i, j) = drv.Text.ToString() j += 1 Next j = 1 i += 1 Next Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub
Fuente: http://paradageek.16mb.com/2012/06/exportar-a-excel-desde-listview-en-visual-basic/#&panel1-7
gracias...me sirvio de mucho..saludos
ResponderEliminar