E
eighteenzl
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.SpeedButton1Click(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(edit1.Text);
{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
iRow := BeginRow;
iCol := BeginCol;
while trim(Excel.WorkSheets[2].Cells[iRow,iCol].value) <> '' do begin
with ADOQry_main do begin
Append;
Fields[0].AsString := trim(Excel.WorkSheets[2].Cells[iRow,iCol].value);
Fields[1].AsString := trim(Excel.WorkSheets[2].Cells[iRow,iCol+1].value);
Fields[2].Asstring := trim(Excel.WorkSheets[2].Cells[iRow,iCol+2].value);
Fields[3].Asstring := trim(Excel.WorkSheets[2].Cells[iRow,iCol+3].value);
Fields[4].AsString := trim(Excel.WorkSheets[2].Cells[iRow,iCol+4].value);
iRow := iRow + 1;
end;
end;
Excel.Quit;
ADOQry_main.UpdateStatus ;
except
Application.MessageBox('导入数据出错!请检查文件的格式是否正确!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Excel.Quit;
end;
MessageBox(GetActiveWindow(), '数据导入成功!', '警告', MB_OK +
MB_ICONWARNING);
end;
各位大侠,我在写EXECL导入的时候遇到了一些问题,请各位指点一下,谢谢
帮我注释一下,整个过程就 Excel :=CreateOLEObject('Excel.Application');
这条报错,基中CreateOLEObject是这个未申明!
我是没有引用任何函数的.
谢谢!请知道的多多指教!
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(edit1.Text);
{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
iRow := BeginRow;
iCol := BeginCol;
while trim(Excel.WorkSheets[2].Cells[iRow,iCol].value) <> '' do begin
with ADOQry_main do begin
Append;
Fields[0].AsString := trim(Excel.WorkSheets[2].Cells[iRow,iCol].value);
Fields[1].AsString := trim(Excel.WorkSheets[2].Cells[iRow,iCol+1].value);
Fields[2].Asstring := trim(Excel.WorkSheets[2].Cells[iRow,iCol+2].value);
Fields[3].Asstring := trim(Excel.WorkSheets[2].Cells[iRow,iCol+3].value);
Fields[4].AsString := trim(Excel.WorkSheets[2].Cells[iRow,iCol+4].value);
iRow := iRow + 1;
end;
end;
Excel.Quit;
ADOQry_main.UpdateStatus ;
except
Application.MessageBox('导入数据出错!请检查文件的格式是否正确!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Excel.Quit;
end;
MessageBox(GetActiveWindow(), '数据导入成功!', '警告', MB_OK +
MB_ICONWARNING);
end;
各位大侠,我在写EXECL导入的时候遇到了一些问题,请各位指点一下,谢谢
帮我注释一下,整个过程就 Excel :=CreateOLEObject('Excel.Application');
这条报错,基中CreateOLEObject是这个未申明!
我是没有引用任何函数的.
谢谢!请知道的多多指教!