Hej sök i forumet efter 'hur spara fil snabbare'Exportera listview till excel i VB.NET
Mitt problem är att hitta på en bra kod för att exportera synlig data i Listview till excel någon som har en bra kod för detta.
Jag har gjort följande kod utan succé
Dim appexcel As Excel.Application
Dim xlsleverans As String
xlsleverans = "C:\Leverans.xls"
appexcel = New Excel.Application
appexcel.Workbooks.Open(xlsleverans)
appexcel.Visible = False
appexcel.Worksheets(1).Cells(1, 1).Value = "Användare:"
appexcel.Worksheets(1).Cells(1, 2).Value = "Kund:"
appexcel.Worksheets(1).Cells(1, 3).Value = "Kundupplysning:"
appexcel.Worksheets(1).Cells(1, 4).Value = "Utskickstyp:"
appexcel.Worksheets(1).Cells(1, 5).Value = "Panel:"
appexcel.Worksheets(1).Cells(1, 6).Value = "Frekvens:"
appexcel.Worksheets(1).Cells(1, 7).Value = "Antal Dagar:"
appexcel.Worksheets(1).Cells(1, 8).Value = "Datum:"
appexcel.Worksheets(1).Cells(1, 9).Value = "Diff:"
appexcel.Worksheets(1).Cells(1, 10).Value = "Anteckningar:"
'appexcel.Worksheets(1).Cells(1, 11).Value = "Summa:"
' On Error GoTo fin
Co = 0
It = 0
Dim st As String
Dim itm As ListViewItem
Do
appexcel.Worksheets(1).Cells(2 + Co, 1).Value = ListView3.Items.Item(1 + It)
appexcel.Worksheets(1).Cells(2 + Co, 2).Value = ListView3.Items.Item(1 + It).SubItems(1)
appexcel.Worksheets(1).Cells(2 + Co, 3).Value = ListView3.Items.Item(1 + It).SubItems(2)
appexcel.Worksheets(1).Cells(2 + Co, 4).Value = ListView3.Items.Item(1 + It).SubItems(3)
appexcel.Worksheets(1).Cells(2 + Co, 5).Value = ListView3.Items.Item(1 + It).SubItems(4)
appexcel.Worksheets(1).Cells(2 + Co, 6).Value = ListView3.Items.Item(1 + It).SubItems(5)
appexcel.Worksheets(1).Cells(2 + Co, 7).Value = ListView3.Items.Item(1 + It).SubItems(6)
appexcel.Worksheets(1).Cells(2 + Co, 8).Value = ListView3.Items.Item(1 + It).SubItems(7)
appexcel.Worksheets(1).Cells(2 + Co, 9).Value = ListView3.Items.Item(1 + It).SubItems(8)
appexcel.Worksheets(1).Cells(2 + Co, 10).Value = ListView3.Items.Item(1 + It).SubItems(9)
'appexcel.Worksheets(1).Cells(2 + Co, 11).Value = ListView3.Items.Item(1 + It).SubItems(11)
Co = Co + 1
It = It + 1
Loop
'Exit Sub
For i = 1 To 11
appexcel.Worksheets(1).Cells(1, i).Font.Bold = True
appexcel.Worksheets(1).Cells(1, i).Font.Size = 8
'appexcel.Worksheets(1).Cells(1, i).HorizontalAlignment = xlCenter
'appexcel.Worksheets(1).Cells(1, i).VerticalAlignment = xlCenter
Next i
For j = 1 To 11
'appexcel.Worksheets(1).Cells(2, j).HorizontalAlignment = xlCenter
Next j
fin:
End Sub
Jag får ett fel i början av min Loop (appexcel.Worksheets(1).Cells(2 + Co, 1).Value = ListView3.Items.Item(1 + It)).
Listviewn är satt som detaljerad lista.
Kan man få denna till att fungare eller har någon en bättre lösning?
MVH
JörgenSv: Exportera listview till excel i VB.NET
hade uppe den tråden nyligen