Delphi 如何使用ADO将值插入Excel文件?
我使用以下代码在Excel文件中插入值:Delphi 如何使用ADO将值插入Excel文件?,delphi,ado,tadoquery,Delphi,Ado,Tadoquery,我使用以下代码在Excel文件中插入值: sAppend:='INSERT INTO ["Excel 8.0;Database=' + Edit1.Text + ';"].[Sheet1$] (d) ' + FormatDateTime('d/m/yyyy', now)+';'; AdoQuery1.SQL.Text:=sAppend; AdoQuery1.ExecSQL; 前面的例程已完全显示 连接到Excel文件 procedure TForm1.ConnectToExcel; var
sAppend:='INSERT INTO ["Excel 8.0;Database=' + Edit1.Text + ';"].[Sheet1$] (d) ' + FormatDateTime('d/m/yyyy', now)+';';
AdoQuery1.SQL.Text:=sAppend;
AdoQuery1.ExecSQL;
前面的例程已完全显示
连接到Excel文件
procedure TForm1.ConnectToExcel;
var strConn : widestring;
begin
strConn:='Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=' + Edit1.Text + ';' +
'Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";Persist Security Info=False';
AdoConnection1.Connected:=False;
AdoConnection1.ConnectionString:=strConn;
try
AdoConnection1.Open;
AdoConnection1.GetTableNames(ComboBox1.Items,True);
except
ShowMessage('Unable to connect to Excel, make sure the workbook ' + Edit1.Text + 'exist!');
raise;
end;
end;(*ConnectToExcel*)
procedure TForm1.FetchData;
begin
StatusBar1.SimpleText:='';
if not AdoConnection1.Connected then ConnectToExcel;
AdoQuery1.Close;
AdoQuery1.SQL.Text:=Edit2.Text;
try
AdoQuery1.Open;
except
ShowMessage('Unable to read data from Excel, make sure the query ' + Edit1.Text + ' is meaningful!');
raise;
end;
end;
谁能告诉我我做错了什么
错误为“INSERT INTO语句中的语法错误”。找到了解决方案:
sAppend:='INSERT INTO [Sheet1$] (d) values ("' + DateToStr(now) +'")';
AdoQuery1.SQL.Text:=sAppend;
AdoQuery1.ExecSQL;
请发布完整的源代码,包括您正在使用的连接字符串和收到的错误。并祈祷这将适用于使用不同语言环境的用户。