0

I want to connect to an Excel file with UniDAC

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

How can I Connect to an Excel File with UniDAC ? is it possible ?

I can connect to excel file with ADO but I want to use UniDAC

  • I`m using Delphi XE6
Mahmoud_Mehri
  • 1,643
  • 2
  • 20
  • 38
  • 1
    No you can't. UniDAC is not an ADO wrapper, but it does include an MS SQL native client. What makes you think UniDAC is useful for connecting any arbitrary ADO object? It has ODBC but not OLEDB connectors, if I remember correctly. So use ADO. – Warren P Jan 05 '16 at 15:27
  • If you want an ultra-lightweight alternative, you can find libraries for Delphi that will read or write .XLS files and extract data from them directly, and if you are going to require Excel installed, you could use OLE Automation instead of OLEDB or ODBC, to access Excel. – Warren P Jan 05 '16 at 15:39

2 Answers2

1

Unidac, as you have discovered provides an ODBC data access driver. 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). And that's just the start...

A better option for Delphi is to go via ADO or... 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.

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

Freddie Bell
  • 2,186
  • 24
  • 43
0
FUniConnection1.ConnectString := Format('Provider Name=ODBC;Server="DRIVER=Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb); DBQ=%s"', [FileName]);
Tyler2P
  • 2,324
  • 26
  • 22
  • 31