Feeling of using ADO to connect Excel in Delphi

Source: Internet
Author: User
Tags microsoft access database
Feeling of using ADO to connect excel in Delphi
By panther666 use ADO to connect to Excel in Delphi today (I have read it in a book before, review it -_-!!), I have gained some benefits and do not dare to enjoy them exclusively. Part 1: 1. the Provider of ole db that sets the ConnectionString attribute of ADOConnection should select Microsoft Jet 4.0 ole db Provider (this is the driver used to connect to the Access database, but can also open the Excel file ), click "Next". 2. select a database name. Note: the Excel file extension is *. xls, and the default file type is Microsoft Access database (*. mdb), we select "all files (*. *) ", then select the Excel file to be connected !! Enter 2007.xls directly. In this case, do not press the "test connection" button. Otherwise, an error dialog box will appear. You can try it. For more information, see pai_^ 3. On the "all" tab, find "Extended Properties", double-click it, or press the "Edit value" button to set Extended Properties to "Excel 8.0 ". 4. Go back to the "connection" tab and click "test connection. Connection test successful !!! Finally, the parameters in ConnectionString after setting are:
Provider = Microsoft. Jet. OLEDB.4.0
Data Source=2007.xls // because it is in the current path
Extended Properties = Excel 8.0
Persist Security Info = False Part 2: Use ADOTable, ADODataSet, and ADOQuery to connect to the ADOConnection. Of course, you can directly set the ConnectionString attribute of ADOTable, ADODataSet, or ADOQuery. 1. ADOTable settings: The TableName attribute value of a. ADOTable: the system automatically generates Sheet 1 $, sheet 2 $, and Sheet 3 $ for Excel. Set "Active" directly to "true". The system reports SQL statement format errors and other information. B. Find the TableDirect attribute and set it to True. Because access to Excel files is a direct access to data files, not through SQL statements to operate on the cursor access. Set "Active" to "true. Success !! ^_^ C. You can change Sheet1 $, Sheet2 $, and Sheet3 $ in the TableName attribute to [Sheet1 $], [Sheet2 $], and [Sheet3 $] without using the TableDirect attribute. Yes, you just need to add. 2. ADODataSet settings: a. You only need to set the CommandType attribute to cmdTableDirect, select the worksheet, and set Active to true. B. You can also set the CommandType attribute to cmdTable and change the CommandText attribute to [Sheet1 $], [Sheet2 $], and [Sheet3 $]. 3. ADOQuery settings: the SQL attributes are as follows:

Select * from [sheet1 $] Summary: review what you learned before and try new connection methods, which is helpful for deepening your memory. I found that the worksheet name should be followed by an additional $ symbol. In addition, after the ADOTable, ADODataSet, or ADOQuery is enabled, their CursorType will automatically become ctStatic.
Application Environment: Delphi7.0 + win2003 Enterprise Edition

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.