具体情况是这样的:我要通过选择EXCEL表然后导入到access数据库中,excel表中有4列N行,然后access数据库中也有4个字段分别对应excel表中的4列数据,下面是我写的代码,不能运行,希望高手帮帮忙!~~
procedure TForm1.FormCreate(Sender: TObject);
begin
ADOQuery1.Open;
ClientDataSet1.Open;
try
ADOConnection1.Connected:=true;
Except
Application.MessageBox('数据库连接失败,请检查参数!','警告',mb_iconwarning)
end;
end;procedure TForm1.RzBitBtn1Click(Sender: TObject);
var
i:integer;
excela:string;
excelb:string;
excelc:string;
exceld:string;
ExcelApp,workbook,ExcelRowCount:oleVariant;
begin
if RzOpenDialog1.Execute then
begin
try
ExcelApp:=CreateOleObject('Excel.Application');提示未定义 WorkBook := ExcelApp.WorkBooks.Open(RzOpenDialog1.FileName);//使用opendialog对话框指定
ExcelApp.Visible := false;
ExcelRowCount := WorkBook.WorkSheets[1].UsedRange.Rows.Count;
ADOQuery1.Open;
for i := 1 to excelrowcount + 1 do
begin
excela:=ExcelApp.cells[i,1].value;
excelb:=ExcelApp.cells[i,2].value;
excelc:=ExcelApp.cells[i,3].value;
exceld:=ExcelApp.cells[i,4].value;
ClientDataSet1.Append;
ClientDataSet1.FieldByName('姓名').asstring:=excela;
ClientDataSet1.FieldByName('日期').asstring := excelb;
ClientDataSet1.FieldByName('签到时间').asstring := excelc;
ClientDataSet1.FieldByName('签退时间').AsString:= exceld;
ClientDataSet1.post;
ClientDataSet1.ApplyUpdates(-1);
ADOQuery1.UpdateBatch;
showmessage('导入数据成功!')
finally[Error] Unit1.pas(78): 'END' expected but 'FINALLY' found
WorkBook.Close;
ExcelApp.Quit;
ExcelApp := Unassigned;
WorkBook := Unassigned;
end;
end;
end;
end.
procedure TForm1.FormCreate(Sender: TObject);
begin
ADOQuery1.Open;
ClientDataSet1.Open;
try
ADOConnection1.Connected:=true;
Except
Application.MessageBox('数据库连接失败,请检查参数!','警告',mb_iconwarning)
end;
end;procedure TForm1.RzBitBtn1Click(Sender: TObject);
var
i:integer;
excela:string;
excelb:string;
excelc:string;
exceld:string;
ExcelApp,workbook,ExcelRowCount:oleVariant;
begin
if RzOpenDialog1.Execute then
begin
try
ExcelApp:=CreateOleObject('Excel.Application');提示未定义 WorkBook := ExcelApp.WorkBooks.Open(RzOpenDialog1.FileName);//使用opendialog对话框指定
ExcelApp.Visible := false;
ExcelRowCount := WorkBook.WorkSheets[1].UsedRange.Rows.Count;
ADOQuery1.Open;
for i := 1 to excelrowcount + 1 do
begin
excela:=ExcelApp.cells[i,1].value;
excelb:=ExcelApp.cells[i,2].value;
excelc:=ExcelApp.cells[i,3].value;
exceld:=ExcelApp.cells[i,4].value;
ClientDataSet1.Append;
ClientDataSet1.FieldByName('姓名').asstring:=excela;
ClientDataSet1.FieldByName('日期').asstring := excelb;
ClientDataSet1.FieldByName('签到时间').asstring := excelc;
ClientDataSet1.FieldByName('签退时间').AsString:= exceld;
ClientDataSet1.post;
ClientDataSet1.ApplyUpdates(-1);
ADOQuery1.UpdateBatch;
showmessage('导入数据成功!')
finally[Error] Unit1.pas(78): 'END' expected but 'FINALLY' found
WorkBook.Close;
ExcelApp.Quit;
ExcelApp := Unassigned;
WorkBook := Unassigned;
end;
end;
end;
end.
begin
excela:=ExcelApp.cells[i,1].value;
excelb:=ExcelApp.cells[i,2].value;
excelc:=ExcelApp.cells[i,3].value;
exceld:=ExcelApp.cells[i,4].value;
ClientDataSet1.Append;
ClientDataSet1.FieldByName('姓名').asstring:=excela;
ClientDataSet1.FieldByName('日期').asstring := excelb;
ClientDataSet1.FieldByName('签到时间').asstring := excelc;
ClientDataSet1.FieldByName('签退时间').AsString:= exceld;
ClientDataSet1.post;
ClientDataSet1.ApplyUpdates(-1);
ADOQuery1.UpdateBatch;
showmessage('导入数据成功!')
end ; //这里补一个END
finally[Error] Unit1.pas(78): 'END' expected but 'FINALLY' found
CoInitialize(nil);
ExcelApp:=CreateOleObject('Excel.Application');
...
finally
CoUninitialize;
end;