小弟遇一问题,为什么在执行线程时,只复制了一个表,而后面的代码不执行?
代码如下:
这是线程那个单元
unit Unit2;
interface
uses
Classes,unit1, Windows, Messages, SysUtils, Variants, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, DB, ADODB, ComCtrls,comobj,excel2000,Activex;
type
mythread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;
implementation
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure mythread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ mythread }
procedure mythread.Execute;
var
xlApp, xlBook, xlSheet,xlQuery: Variant;
filename : string;
begin
CoInitialize(nil);
form1.button1.Enabled:=false;
form1.savedialog1.FileName:='文化路'+datetostr(date);
form1.savedialog1.Execute;
filename:=form1.savedialog1.FileName;
if filename='' then
begin
exit;
end;
form1.adodataset1.Close;
form1.adodataset1.CommandText:='select * from 文化路_c';
form1.adodataset1.Open;
if form1.adodataset1.IsEmpty then
begin
showmessage('没有数据可以导出!');
exit;
end;
xlApp := CreateOleObject('Excel.Application');
xlBook := xlApp.Workbooks.Add;
xlSheet := xlBook.Worksheets['sheet1'];
xlApp.Visible := false;
xlQuery := xlSheet.QueryTables.Add(form1.adodataset1.Recordset ,xlSheet.Range['A1']);
xlQuery.FieldNames := true;
xlQuery.RowNumbers := False;
xlQuery.FillAdjacentFormulas := False;
xlQuery.PreserveFormatting := True;
xlQuery.RefreshOnFileOpen := False;
xlQuery.BackgroundQuery := True;
xlQuery.RefreshStyle := xlOverwriteCells;
xlQuery.SaveData := True;
xlQuery.AdjustColumnWidth := True;
xlQuery.RefreshPeriod := 0;
xlQuery.PreserveColumnInfo := True;
xlQuery.Refresh;
xlapp.DisplayAlerts:=false;
xlapp.Workbooks[1].SaveAs(filename);
xlapp.quit;
xlApp := Unassigned;
xlBook := Unassigned;
form1.progressbar1.Position:=25;
CoUninitialize;
if FileExists(filename) then
begin
CoInitialize(nil);
form1.adodataset1.Close;
form1.adodataset1.CommandText:='select * from 大同路_c';
form1.adodataset1.Open;
filename:=stringreplace(filename,'文化路','大同路',[rfReplaceAll]) ;
if form1.adodataset1.IsEmpty then
begin
showmessage('没有数据可以导出!');
exit;
end;
xlApp := CreateOleObject('Excel.Application');
xlBook := xlApp.Workbooks.Add;
xlSheet := xlBook.Worksheets['sheet1'];
xlApp.Visible := false;
xlQuery := xlSheet.QueryTables.Add(form1.adodataset1.Recordset ,xlSheet.Range['A1']);
xlQuery.FieldNames := true;
xlQuery.RowNumbers := False;
xlQuery.FillAdjacentFormulas := False;
xlQuery.PreserveFormatting := True;
xlQuery.RefreshOnFileOpen := False;
xlQuery.BackgroundQuery := True;
xlQuery.RefreshStyle := xlOverwriteCells;
xlQuery.SaveData := True;
xlQuery.AdjustColumnWidth := True;
xlQuery.RefreshPeriod := 0;
xlQuery.PreserveColumnInfo := True;
xlQuery.Refresh;
xlapp.DisplayAlerts:=false;
xlapp.Workbooks[1].SaveAs(filename);
xlapp.quit;
xlApp := Unassigned;
xlBook := Unassigned;
form1.progressbar1.Position:=50;
end;
if FileExists(filename) then
begin
form1.adodataset1.Close;
form1.adodataset1.CommandText:='select * from 政一街e';
form1.adodataset1.Open;
filename:=stringreplace(filename,'大同路','政一街',[rfReplaceAll]) ;
if form1.adodataset1.IsEmpty then
begin
showmessage('没有数据可以导出!');
exit;
end;
xlApp := CreateOleObject('Excel.Application');
xlBook := xlApp.Workbooks.Add;
xlSheet := xlBook.Worksheets['sheet1'];
xlApp.Visible := false;
xlQuery := xlSheet.QueryTables.Add(form1.adodataset1.Recordset ,xlSheet.Range['A1']);
xlQuery.FieldNames := true;
xlQuery.RowNumbers := False;
xlQuery.FillAdjacentFormulas := False;
xlQuery.PreserveFormatting := True;
xlQuery.RefreshOnFileOpen := False;
xlQuery.BackgroundQuery := True;
xlQuery.RefreshStyle := xlOverwriteCells;
xlQuery.SaveData := True;
xlQuery.AdjustColumnWidth := True;
xlQuery.RefreshPeriod := 0;
xlQuery.PreserveColumnInfo := True;
xlQuery.Refresh;
xlapp.DisplayAlerts:=false;
xlapp.Workbooks[1].SaveAs(filename);
xlapp.quit;
xlApp := Unassigned;
xlBook := Unassigned;
form1.progressbar1.Position:=75;
end;
if FileExists(filename) then
begin
form1.adodataset1.Close;
form1.adodataset1.CommandText:='select * from 集团用户';
form1.adodataset1.Open;
filename:=stringreplace(filename,'政一街','集团用户',[rfReplaceAll]) ;
if form1.adodataset1.IsEmpty then
begin
showmessage('没有数据可以导出!');
exit;
end;
xlApp := CreateOleObject('Excel.Application');
xlBook := xlApp.Workbooks.Add;
xlSheet := xlBook.Worksheets['sheet1'];
xlApp.Visible := false;
xlQuery := xlSheet.QueryTables.Add(form1.adodataset1.Recordset ,xlSheet.Range['A1']);
xlQuery.FieldNames := true;
xlQuery.RowNumbers := False;
xlQuery.FillAdjacentFormulas := False;
xlQuery.PreserveFormatting := True;
xlQuery.RefreshOnFileOpen := False;
xlQuery.BackgroundQuery := True;
xlQuery.RefreshStyle := xlOverwriteCells;
xlQuery.SaveData := True;
xlQuery.AdjustColumnWidth := True;
xlQuery.RefreshPeriod := 0;
xlQuery.PreserveColumnInfo := True;
xlQuery.Refresh;
xlapp.DisplayAlerts:=false;
xlapp.Workbooks[1].SaveAs(filename);
xlapp.quit;
xlApp := Unassigned;
xlBook := Unassigned;
form1.progressbar1.Position:=100;
showmessage('我导得好辛苦啊!!') ;
form1.progressbar1.Position:=0;
end;
CoUninitialize;
end;
end.