How to use ADO to manipulate an Excel file

zhaozj2021-02-17  47

How to use ADO to manipulate an Excel file

In daily life, there are usually a lot of table files to use Excel storage. There are many ways to access the Excel form. In the Delphi, you can manipulate the data in Excel through controls such as Excelapplication, Excelworkbook, Excelworksheet. But we cannot manipulate the Excel files in ADO The SHEET, ADO control will tell you "[Microsoft] [ODBC Excel Driver] Microsoft Jet database engine can't find object 'sheet1'. Please determine if the object exists and correctly writes its name and path.

So how can I control the EXCEL correctly?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

First use ADO to connect Excel, as for how to connect Excel, I don't want me to say it.

Then this is a key: Open Excel, first "insert" -> "name" -> "definition", as shown:

Enter a name, such as: OK, press the "Add" button, then specify the reference location, as shown in the figure:

Finally, press "OK" and then store, this key step is completed.

Now you can use ADOQUERY or ADOTABLE to have a table name "OK".

Note: 1. You can define multiple names in an Excel file, when multiple tables are used

2. This method cannot be used in the elements such as Chart in Excel

转载请注明原文地址:https://www.9cbs.com/read-28528.html

New Post(0)