1. First, right-click "Reference" in "project" in "solution" and introduce the Exel component in the COM component, as shown in: (versions may be different, which does not affect, I installed Office 2003)
2. Program To add the following statement:
Imports Microsoft. Office. InterOP
3. Create a new process function and output it to excel:
Private sub Button2_click ( Byval Sender As System. object, Byval E As System. eventargs) Handles Button2.click
Dim Myexcel As New excel. Application
Myexcel. Visible = True
Myexcel. workbooks. Add ()
Dim Col As Integer
Dim Row As Integer
Dim Col1 As Integer
Myexcel. worksheets ("sheet1"). Activate ()
'The following is a column name for each column that is output to an Excel table.
Myexcel. cells (1, 1). value = "unit name"
Myexcel. cells (1, 2). value = "unit type"
Myexcel. cells (1, 3). value = "office address"
Myexcel. cells (1, 4). value = "mailing address"
Myexcel. cells (1, 5). value = "office phone"
Myexcel. cells (1, 6). value = "membership payment"
Myexcel. cells (1, 7). value = "payment amount"
'Next, We will output the data in the dataset to each column in Excel. My dataset is "dsresults", which can be modified as appropriate for each person.
For Row = 0 To Dsresults. Tables ("Results"). Rows. Count-1
For Col = 1 To Dsresults. Tables ("Results"). Columns. Count-1
Myexcel. cells (row + 2, col). value = dsresults. Tables ("Results"). Rows (ROW) (COL)
Next
'Each column in Excel is automatically adjusted based on the filled data
Myexcel. activesheet. Columns. autofit ()
Next
End sub
4. The final output result is: