//以下为数据导入的关键代码
//第三方控件:flatystyle,suipack,Raize,fastreport,IP4000,其实不用也没关//系,在delphibox上都有,希望你能调试成功!
procedure TForm1.N9Click(Sender: TObject);
var
x:integer; //统计出excel中的记录数;
i : integer;
j : integer;
EParam : OleVariant;
DocuType : OleVariant;
wkbk : _WorkBook;
S:string;
begin
merlin.play('Wave');
merlin.Speak('注意到入的excel文件要符合数据库标准呀!','');
if application.MessageBox('此动作会删除以往的记录 确认要执行吗?','提示', MB_YESNO)=IDYES then
begin
FlatProgressBar1.Visible:=true;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('delete * from temp');
adoquery1.ExecSQL;
adoquery1.Close;
adoquery1.Close;
opendialog1.InitialDir:=ExtractFileDir(paramstr(0));
//文件打开的初始路径
opendialog1.Execute;
Try
ExcelApplication1.Connect;
Except
Showmessage('Excel文件打开失败!');
Exit;
End;
ExcelApplication1.Visible[0]:=False;
ExcelApplication1.Caption:='Excel数据文件';
EParam:=EmptyParam;
DocuType:=0;
try
wkBk:=ExcelApplication1.Workbooks.Add(EParam, DocuType);
wkBk:=ExcelApplication1.WorkBooks.Open(opendialog1.FileName,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,DocuType,DocuType);
except
begin
ExcelApplication1.Disconnect;//出现异常情况时关闭
ExcelApplication1.Quit;
showmessage('请选择EXCEL数据表格!');
exit;
end;
end;
ExcelWorkbook1.ConnectTo(ExcelApplication1.ActiveWorkbook);//ExcelWorkbook1与Eexcelapplication1建立连接
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);//Excelworksheet1与Excelworkbook1建立连接
// x:=ExcelWorksheet1.Cells.Row;
// showmessage(inttostr(x));
//开始从EXCEL中取数,放到stringgrid中,取完数后关闭EXCEL
for i:=1 to 500 do //此数量为预计数量
begin
if trim(excelworksheet1.cells.item[i,1])<>'' then //item[i+1,1]
begin
AdoTable1.Append;
AdoTable1.fieldbyname('pro_class').value:=ExcelWorksheet1.Cells.Item[i,1];
AdoTable1.fieldbyname('pcl_name').value:=ExcelWorksheet1.Cells.Item[i,2];
AdoTable1.fieldbyname('pro_id').value:=ExcelWorksheet1.Cells.Item[i,3];
AdoTable1.fieldbyname('pro_name').value:=ExcelWorksheet1.Cells.Item[i,4];
AdoTable1.fieldbyname('pcd_date').value:=ExcelWorksheet1.Cells.Item[i,5];
AdoTable1.fieldbyname('pcd_old_price').value:=ExcelWorksheet1.Cells.Item[i,6];
AdoTable1.fieldbyname('pcd_new_price').value:=ExcelWorksheet1.Cells.Item[i,7];
AdoTable1.fieldbyname('pu_com_id').value:=ExcelWorksheet1.Cells.Item[i,8];
AdoTable1.fieldbyname('sor_id').value:=ExcelWorksheet1.Cells.Item[i,9];
AdoTable1.fieldbyname('pcd_reason').value:=ExcelWorksheet1.Cells.Item[i,10];
AdoTable1.fieldbyname('pro_name').value:=ExcelWorksheet1.Cells.Item[i,11];
AdoTable1.Post;
Application.ProcessMessages;
FlatProgressBar1.StepIt;
if FlatProgressBar1.Position=FlatProgressBar1.Max then
FlatProgressBar1.Position:=FlatProgressBar1.min;
// ProgressBar1.Position:=ProgressBar1.Position+1;
// FlatGauge1.Progress:=FlatGauge1.Progress+1;
// ProgressBar1.StepIt;
// showmessage(inttostr(i));
end
end;
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
FlatProgressBar1.Position:=FlatProgressBar1.max;
adoquery1.close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('UPDATE temp SET p_date = left(pcd_date,10)');
adoquery1.ExecSQL;
adoquery1.close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select count(*) as co from temp');
adoquery1.Open;
i:=adoquery1.fieldbyname('co').AsInteger;
showmessage('数据转换完毕!共有'+inttostr(i)+'条记录被导入!');
FlatProgressBar1.Visible:=false;
end;
excle转换到access
需积分: 50 196 浏览量
2006-02-23
09:05:59
上传
评论
收藏 3.61MB RAR 举报
普通网友
- 粉丝: 882
- 资源: 2万+