动态选择任何excel数据文件导入DBGRID中无法显示的问题请教(100分)

  • 主题发起人 主题发起人 jarod2005
  • 开始时间 开始时间
J

jarod2005

Unregistered / Unconfirmed
GUEST, unregistred user!
本人想通过OpenDialo控件动态链接任何EXCEL数据文件导入到DBGRID中显示,但是无法总是出现无法显示的错误信息,一直没找到解决的方法,以下是相关代码,请教哪位大侠能指点一二。
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
OpenDialog1: TOpenDialog;
ADOConnection1: TADOConnection;
DBGrid1: TDBGrid;
ADOTable1: TADOTable;
DataSource1: TDataSource;
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
pathstr: string;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
opendialog1.filename:='*.xls';
if opendialog1.Execute then
begin
pathstr:=opendialog1.FileName;
edit1.Text:=pathstr;
Adoconnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;'
+'Password="";Data Source='''+pathstr+ ''';'
+ 'Extended Properties=Excel 8.0;Persist Security Info=false';
ADOConnection1.connected:=true;
ADOTable1.TableName:=pathstr;
ADOTable1.active:=true;
end;
end;
end.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
664
import
I
I
回复
0
查看
694
import
I
后退
顶部