C
cf83325
Unregistered / Unconfirmed
GUEST, unregistred user!
导入成功了,但是只导入了一条记录,如何实现批量导入啊。。。
procedure TForm1.btninClick(Sender: TObject);
const
BeginRow = 3; BeginCol = 1;
var
Excel: OleVariant;
iRow,iCol : integer;
xlsFilename: string;
begin
OpenDialog1.Title := '请选择相应的Excel文件';
OpenDialog1.Filter := 'Excel(*.xls)|*.xls';
if OpenDialog1.Execute then
edit1.Text := OpenDialog1.FileName;
if (trim(edit1.Text) = '') then
begin
MessageBox(GetActiveWindow(), '请正确选择相关路径!', '警告', MB_OK +
MB_ICONWARNING);
exit;
end;
xlsFilename := trim(OpenDialog1.FileName);
try
Excel := CreateOLEObject('Excel.Application');
except
Application.MessageBox('Excel没有安装!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Exit;
end;
Excel.Visible := false;
Excel.WorkBooks.Open(xlsFilename);
try
with ADOTable1 do
begin
Append;
FieldByName('招待时间').AsString:=Excel.WorkSheets[1].Cells[2,1].Value;
FieldByName('对象').AsString:=Excel.WorkSheets[1].Cells[2,2].Value;
FieldByName('人数').AsString:=Excel.WorkSheets[1].Cells[2,3].Value; //cell是excel里面的单元格
FieldByName('金额').AsString:=Excel.WorkSheets[1].Cells[2,4].Value;
FieldByName('经办').AsString:=Excel.WorkSheets[1].Cells[2,5].Value;
Post;
end;
except
Application.MessageBox('导入数据出错!请检查文件的格式是否正确!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Excel.Quit;
end;
MessageBox(GetActiveWindow(), '数据导入成功!', '警告', MB_OK +
MB_ICONWARNING);
end;
procedure TForm1.btninClick(Sender: TObject);
const
BeginRow = 3; BeginCol = 1;
var
Excel: OleVariant;
iRow,iCol : integer;
xlsFilename: string;
begin
OpenDialog1.Title := '请选择相应的Excel文件';
OpenDialog1.Filter := 'Excel(*.xls)|*.xls';
if OpenDialog1.Execute then
edit1.Text := OpenDialog1.FileName;
if (trim(edit1.Text) = '') then
begin
MessageBox(GetActiveWindow(), '请正确选择相关路径!', '警告', MB_OK +
MB_ICONWARNING);
exit;
end;
xlsFilename := trim(OpenDialog1.FileName);
try
Excel := CreateOLEObject('Excel.Application');
except
Application.MessageBox('Excel没有安装!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Exit;
end;
Excel.Visible := false;
Excel.WorkBooks.Open(xlsFilename);
try
with ADOTable1 do
begin
Append;
FieldByName('招待时间').AsString:=Excel.WorkSheets[1].Cells[2,1].Value;
FieldByName('对象').AsString:=Excel.WorkSheets[1].Cells[2,2].Value;
FieldByName('人数').AsString:=Excel.WorkSheets[1].Cells[2,3].Value; //cell是excel里面的单元格
FieldByName('金额').AsString:=Excel.WorkSheets[1].Cells[2,4].Value;
FieldByName('经办').AsString:=Excel.WorkSheets[1].Cells[2,5].Value;
Post;
end;
except
Application.MessageBox('导入数据出错!请检查文件的格式是否正确!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Excel.Quit;
end;
MessageBox(GetActiveWindow(), '数据导入成功!', '警告', MB_OK +
MB_ICONWARNING);
end;