I could use some help. I have a program where I put data into a list view in VB.net. I then use the code below in a button click to export the content into a excel file where I can then save it. however I plan to add alot more data to the list view ad would like to auto save the data in the list view to an excel file (where it saves it to disk not an open excel window) and then clears the list view then will repopulate the list view and repet the loop of saving the data to a new excel file on disk.
could anyone help me with the process on how to change this code to make it save it right to disk rather the how it is currently? as it is now it opens a excel document and enters the contents of the listview into that excel document but you have to save it manually.
I normally do C# an I am editing a VB.net program for a client and could use the help.
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() 'MessageBox.Show(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