Public Sub excelexport(ByVal
lvexcel As ListView)
Dim mcd AsNew SaveFileDialog
mcd.ShowDialog()
If mcd.FileName = "" Then
Exit Sub
End If
Dim exapp As Object
Dim wsheet As Object
Dim wbook As Object
exapp = CreateObject("excel.application")
wbook = exapp.Workbooks.Add
wsheet = wbook.worksheets(1)
Dim i, j, mrow AsInteger
mrow =1For i =0To
lvexcel.Columns.Count -1
If lvexcel.Columns(i).Width >0Then
wsheet.Cells(mrow, i +1) = lvexcel.Columns(i).Text
wsheet.Cells(mrow, i +1).Font.bold =TrueEnd If
Next i
For i =0To
lvexcel.Items.Count -1
mrow = mrow +1For j =0To
lvexcel.Items(i).SubItems.Count -1
If lvexcel.Columns(j).Width >0Then
wsheet.Cells(mrow, j +1) = lvexcel.Items(i).SubItems(j).Text
End If
Next j
Next i
wsheet.Columns.EntireColumn.AutoFit()
wsheet.Rows.EntireRow.AutoFit()
If mcd.FileName.Contains(".xls") Then
wsheet.SaveAs(mcd.FileName)
wbook.Close()
Else
wsheet.SaveAs(mcd.FileName & ".xls")
wbook.Close()
End If
exapp = Nothing
MsgBox("Report
Completed")
End Sub
I written above code to export ListView data to Excel file.
It is working fine. but, when listview having more data(morethan 5000 rows) than it is getting slow to export.
is their any code to fasten this export to excel.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Jaish MathewsRank #225 · 11K reputationPosted Mar 31, 2010, 11:01 AM EDT
0
Hi,
Use OLEDB provider. It suports SQL Query to manipulate XL sheets. Just search, lot of articles already available. More over it's managed too.
Jaish MathewsRank #225 · 11K reputationPosted Mar 31, 2010, 11:01 AM EDT
Use OLEDB provider. It suports SQL Query to manipulate XL sheets. Just search, lot of articles already available. More over it's managed too.