|
السلام عليكم ورحمة الله وبركاته Private Sub bttnexcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnexcel.Click ListViewToExcel() End Sub
Private Sub ListViewToExcel() System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
Dim excel As Excel.ApplicationClass = New Excel.ApplicationClass() excel.Application.Workbooks.Add(True)
excel.Cells(1, 1) = "Examinee Details" excel.Range("A1", "C1").Merge()
Dim ColumnIndex As Integer = 0
For Each col As ColumnHeader In Me.lvExaminee.Columns ColumnIndex += 1 excel.Cells(3, ColumnIndex) = col.Name excel.Cells(3, ColumnIndex).EntireRow.font.bold = True excel.Cells(3, ColumnIndex).EntireRow.font.color = RGB(35, 155, 55) Next
Dim rowIndex As Integer = 2 Dim j As Integer Dim Row As ListViewItem For Each Row In Me.lvExaminee.Items rowIndex += 1 ColumnIndex = 1 For j = 0 To Row.SubItems.Count - 1 excel.Cells(rowIndex + 1, ColumnIndex) = Row.SubItems.Item(j).Text ColumnIndex += 1 Next Next excel.Columns.AutoFit() excel.Visible = True End Sub
|