简体   繁体   English

Delphi:使用 UniDAC 连接到 Excel 文件

[英]Delphi : Connecting to an Excel File with UniDAC

I want to connect to an Excel file with UniDAC我想使用 UniDAC 连接到 Excel 文件

I have set Provider property of UniConnection to "ODBC" and Server property to "Excel Files" but there is no option to set Excel File Address我已将 UniConnection 的 Provider 属性设置为“ODBC”,将 Server 属性设置为“Excel Files”,但没有设置 Excel 文件地址的选项

How can I Connect to an Excel File with UniDAC?如何使用 UniDAC 连接到 Excel 文件? is it possible?可能吗?

I can connect to excel file with ADO but I want to use UniDAC我可以使用 ADO 连接到 excel 文件,但我想使用 UniDAC

  • I`m using Delphi XE6我正在使用 Delphi XE6

Unidac, as you have discovered provides an ODBC data access driver. 您已经发现Unidac提供了ODBC数据访问驱动程序。 But as with other drivers that provide access via ODBC, you need to setup an ODBC data source name (DSN) to connect to via Control Panel->Administrative Tools->Data Sources (ODBC). 但是,与其他通过ODBC提供访问的驱动程序一样,您需要设置一个ODBC数据源名称(DSN)以通过控制面板->管理工具->数据源(ODBC)连接。 And that's just the start... 这仅仅是开始...

A better option for Delphi is to go via ADO or... OLE. Delphi的更好选择是通过ADO或OLE。

In the Delphi IDE select Component->Install Packages, and tick either Microsoft Office 2000 Sample Automation Server Wrapper Components or Microsoft Office XP Sample Automation Server Wrapper Components to install the components you can use for accessing Excel this way. 在Delphi IDE中,选择“组件”->“安装软件包”,然后勾选“ Microsoft Office 2000示例自动化服务器包装组件”或“ Microsoft Office XP示例自动化服务器包装组件”以安装可用于以这种方式访问​​Excel的组件。

Here is a comprehensive guide to OLE, though it's a little dated: Delphi 3 - Delphi and Microsoft Office: Automating Excel and Word and Delphi 3 - Delphi and Microsoft Office: Automating Excel and Word - Page 2 这是OLE的综合指南,尽管它有些过时了: Delphi 3-Delphi和Microsoft Office:自动化Excel和WordDelphi 3-Delphi和Microsoft Office:自动化Excel和Word-页面2

FUniConnection1.ConnectString:= Format('Provider Name=ODBC;Server="DRIVER=Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb); DBQ=%s"', [FileName]); FUniConnection1.ConnectString:= Format('Provider Name=ODBC;Server="DRIVER=Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb); DBQ=%s"', [FileName]) ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM