excel|word| export excel| data in the VB6 development environment, I used Excel as a report, in the. NET environment development, I use Crystal Report. But vb.net can also export reports to Excel and Word for output, producing professional-level reports.
The actions are as follows: (Note: First you need to add a reference, select COM, select Microsoft Word 10.0 Object Library and Microsoft Excel 10.0 Object Library component)
1. Create a DataTable first, either as a data source or as another data source.
Dim Table as New DataTable ()
Table = creatable ()
' Assign the column name of the resulting 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 of the resulting table, assigned to cells
For each Row in Table.rows
RowIndex = RowIndex + 1
Colindex = 0
For each Col in Table.columns
Colindex = Colindex + 1
Xlapp.cells (RowIndex, Colindex) = Row (Col.columnname)
Next
Next
With Xlsheet
. Range (. Cells (1, 1),. Cells (1, Colindex)). Font.Name = "Blackbody"
' Set title to bold text
. Range (. Cells (1, 1),. Cells (1, Colindex)). Font.Bold = True
' Title font Bold
. Range (. Cells (1, 1),. Cells (RowIndex, Colindex)). Borders.LineStyle = 1
' Set table border style
End With
' Assign the column name of the resulting table to the cell
Dim Col as DataColumn
Dim Row as DataRow
For each Col in Table.columns
Colindex = Colindex + 1
Otable.cell (1, Colindex). Range.InsertAfter (Col.columnname)
Next
' All rows of the resulting table, assigned to cells
For each Row in Table.rows
RowIndex = RowIndex + 1
Colindex = 0
For each Col in Table.columns
Colindex = Colindex + 1
Otable.cell (RowIndex, Colindex). Range.InsertAfter (Row (col.columnname))
Next
Next
Summary: The Microsoft Word 10.0 (version number) object library provides most of the operations of Word. Similar to the Microsoft Excel Object Library, we can use code to talk to Word and Excel and control them. It is also important that we learn to use the "macros" of Office software. Macros are a combination of a series of word (or other Office software) commands and instructions that generate VB code. We can record "macros" with "Tools/macros/record new macros", and the Code to view "Macros" after the recording is complete to know a series of VB code that implements this function, we copy the code into the VB.net editor, and we can use it after a little change. To do Office development, you must use VBA and macros.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.