VB.net using ADODB to connect to Excel

Source: Internet
Author: User

' Guided into the name space

Imports ADODB

Imports Microsoft.Office.Interop

Private Sub A1 ()

Dim SQL as String
Dim Cnn as New ADODB. Connection
Dim Rs as New ADODB. Recordset
Dim S as String

S = "PROVIDER=ORAOLEDB.ORACLE.1; password= password; Persist Security info=true; User id= username; Data source= Connect Location "
Cnn.open (S)
Rs.cursorlocation = ADODB. Cursorlocationenum.aduseclient

SQL = "Select Img_file. IMG01 from SH01. Img_file "
Rs.Open (SQL, Cnn, 3, 3)
Dim Xls as Excel.Application = New excel.application ' Define EXCEL application
Dim Xlsbook as Excel.Workbook ' Define workbook
Dim xlssheet as Excel.Worksheet ' definition sheet
Xlsbook = Xls.Application.Workbooks.Add ' Add a new workbook
Xlssheet = xlsbook.sheets (1) ' Control handle to worksheet 1th
xls.visible = True ' Show Excel program

Xlssheet.cells (1, 1). Value = "Table 1"

Xlssheet.range ("A2"). CopyFromRecordset (Rs)
Xlssheet.Cells.EntireColumn.AutoFit ()
Xls = Nothing ' releases Excel object
Rs.cancel ()

End Sub

VB.net using ADODB to connect to Excel

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.