level 3
本人对于delphi没有经验,但因为某原因需要今晚做一个小程序,用于多个excel文件其中数据的查重。上网搜了一个源码,是把excel导入到数据库里的。复制了但运行不了,想求个源文件或者源代码,可以直接运行的。
2019年12月17日 10点12分
1
level 3
procedure TForm_qyxxcx.BitBtn2Click(Sender: TObject);
VAR
I,J:INTEGER;
col,row:integer;
MsExcel,WBook,WSheet:OLEVARIANT;
f_temp,strtemp:string;
begin
if Main_form.lwt.Message_Confirm('为预防不可预测情况发生(字段太长、类型不一致等)'+
#10#
13+'强烈建议在导入前备份原来数据,'+
#10#
13+'确认:终止导入'+
#10#
13+'取消:继续导入') then
abort;
cdsDJZY.Open;
cdsDJZY.First;
while not cdsDJZY.Eof do
cdsDJZY.Delete;
cdsDJZY.Close;
cdsDJZY.Open;
try
begin
MsExcel:= CreateOleObject('Excel.Application');
WBook:=MsExcel.Application;
if opendialog1.Execute then //关联到文件
begin
if opendialog1.FileName='' then
abort;
wbook.workbooks.Open(opendialog1.FileName);
end;
WBook.Visible:= true;
WSheet:=WBook.worksheets[1];
end
except
begin
Application.Messagebox('您取消了操作或 Excel 没有安装!','ERROR!', MB_ICONERROR + mb_Ok);
Abort;
end;
end;
row:=WSheet.UsedRange.Rows.Count; //行
col:=WSheet.UsedRange.columns.Count; //列
if (row=0) or (col = 0) then
begin
showmessage('该excel文件没有数据!请确认');
abort;
end;
proform.Show;
proform.ProgressBar1.Max:=row;
with qqyb do
begin
open;
for i:=1 to row-1 do //要增加的行数
begin // 0 人员名称 2 企业名称
//判断是否存在该企业和人员,如果存在,不导入该记录
strtemp:='select * from qyb where qy_name = '''+WSheet.cells[i+1,1].Value+'''';
Main_Form.lwt.DB_AdoQueryRun(qupdate,strtemp);
if qupdate.RecordCount<>0 then // 存在,加入临时表 ,退出本次循环
begin
cdsDJZY.Append ;
cdsDJZY.FieldByName('企业名称').AsString := WSheet.cells[i+1,1].Value;
cdsDJZY.Post;
continue;
end;
Append; //不存在,继续
for j:=0 to col-1 do //列
begin
proform.ProgressBar1.Position:=proform.ProgressBar1.Position+1;
// if adory.Fields[j].FieldKind
Fields[j].Value:= WSheet.cells[i+1,j+1].Value;
end;
Post;
end;
end;
proform.ProgressBar1.Position:=0;
proform.Hide;
比较中意这个源码,但不知道是哪些控件的
2019年12月17日 23点12分
3
所以这个也运行不了
2019年12月17日 23点12分
这个是Delphi操作VBA
2019年12月30日 06点12分
level 3
我是把excel文件的文本复制出来,再粘贴进我的程序,再进行各种处理!
2019年12月26日 17点12分
4
这。。。文本很多就麻烦了
2019年12月27日 11点12分
@渡边菅 exe处理excel过程可能让文件损坏!vba处理遇到版本不兼容你就哭吧!
2019年12月29日 04点12分