vb.net Export Data to Excel

Source: Internet
Author: User
Tags integer range
excel| Export Data----------vb.net export data to Excel-------------

Dim oexcel as New excel.application
Dim obook as Excel.Workbook
Dim osheet as Excel.Worksheet
Dim DataArray as Integer
obook = OExcel.Workbooks.Open ("C:\1.xls")
osheet = obook. Worksheets (1)
Osheet.name = "OK"
Dim Myadapter as New oledb.oledbdataadapter ("SELECT * from List", Module1.dbconn)
Dim myDataSet as New DataSet
Myadapter.fill (myDataSet, "list")
DataGrid1.DataSource = myDataSet. Tables ("list")
Dim I as Integer
Dim Icount as Integer
icount = myDataSet. Tables ("list"). Rows.Count
For i = 0 to ICount-1
DataArray (i, 0) = Datagrid1.item (i, 0)
Next
Osheet.range ("B1"). Resize (100, 1). Value = DataArray
obook. Save ()
oExcel.Quit ()

Add the rows (columns) of data to Excel, and the array of source data corresponds to the rows (columns) of Excel.

The code above uses the DataGrid control, which is the same if you use a table.


The size of the array can be defined by itself, and if the number of data is greater than the range of the array, then the array is the name (who wants to output it with an array):-)

The first time to write a blog, what is wrong to write, master please advise

--------------Finish-------------------------------




Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.