In VB. NET, you can export reports to Excel and Word for output and generate professional reports. The procedure is as follows: (Note: first, add reference, select COM --> Microsoft Word Object Library and Microsoft Excel Object Library)
Private Function CreaTable () As DataTable
Dim dt As New DataTable ()
Dt. Columns. Add ("column 1", GetType (String ))
Dt. Columns. Add ("column 2", GetType (Integer ))
Dt. Columns. Add ("column 3", GetType (String ))
Dt. Columns. Add ("column 4", GetType (String ))
Dim row, row1 As DataRow
Row = dt. NewRow ()
Row! Column 1 = "Row 1"
Row! Column 2 = 1
Row! Column 3 = "d"
Row! Column 4 = ""
Dt. Rows. Add (row)
Row1 = dt. NewRow ()
Row1! Column 1 = "Row 2"
Row1! Column 2 = 12
Row1! Column 3 = "B"
Row1! Column 4 = "c"
Dt. Rows. Add (row1)
Return dt
End Function
'2. Export the table content to Excel
Dim xlApp As New Excel. Application ()
Dim xlBook As Excel. Workbook
Dim xlSheet As Excel. Worksheet
Dim rowIndex As Integer = 1
Dim colIndex As Integer = 0
XlBook = xlApp. Workbooks (). Add
XlSheet = xlBook. Worksheets ("sheet1 ")
Dim Table As New DataTable ()
Table = CreaTable ()
'Assign the column name of the obtained table to the cell.
Dim Col As DataColumn
Dim Row As DataRow
For Each Col In Table. Columns
ColIndex = colIndex + 1
XlApp. Cells (1, colIndex) = Col. ColumnName
Next
'All rows in the table are assigned to the cell.
For Each Row In Table. Rows
RowIndex = rowIndex + 1
ColIndex = 0
For Each Col In Table. Columns