使用ADODataset组件打开Excel电子表格 [英] Using ADODataset component to open an Excel Spreadsheet
问题描述
我使用 ADOdataset 组件来查看Delphi表单上的Excel电子表格。
I'm using ADOdataset component to view an Excel Spreadsheet on a Delphi form.
组件需要 CommandText 属性设置为要打开的工作簿中的电子表格的名称。
The component requires that the CommandText property be set to the name of a spreadsheet in the workbook being opened.
如何设置此属性以打开工作簿中的第一个电子表格,无论名称?
How can I set this property to open the first spreadsheet in the workbook regardless of the name?
procedure TForm1.BitBtn1Click(Sender: TObject);
var XLSFile, CStr : string;
begin
if OpenDialog1.Execute() then
begin
XLSFile := OpenDialog1.FileName;
CStr := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='
+XLSFile+'; Extended Properties=Excel 8.0;Persist Security Info=False';
ADODataSet1.Active := False;
ADODataSet1.ConnectionString := Cstr;
ADODataSet1.CommandText := ??????????;
ADODataSet1.Active := True;
end;
end;
推荐答案
你不能,你必须知道名字的页面。使用 TADOConnection
连接到工作簿,以便您可以调用 GetTableNames
来检索页面名称。 这里的示例。然后,您可以将ADO数据集或ADO查询的 Connection
属性设置为连接对象,并运行查询。
You can't, you have to know the name of the page. Use a TADOConnection
to connect to the work book so that you can call GetTableNames
to retrieve the names of pages. There's an example here. Then you can set the Connection
property of an ADO data set or an ADO query to the connection object and run a query.
这篇关于使用ADODataset组件打开Excel电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!