Application.CreateForm(TfrmProGress, frmProGress);
frmProGress.Show;
MaxRow := ads.RecordCount;
frmProGress.lbl1.Caption := '0/' + IntToStr(MaxRow);
progressstep := 100 / MaxRow;
frmProGress.cxPsbpsb.Position := 0;
ads.First;
xj := ys + 1;
for j := xj to ads.RecordCount + ys do
begin
for i := xs to ads.fieldcount - 3 + xs do
begin
rangs := crs[i] + inttostr(j);
PackListToExcelFile.range[rangs].Font.bold := False;
PackListToExcelFile.range[rangs].font.size := fs;
PackListToExcelFile.range[rangs].Font.Name := 'Courier New';
PackListToExcelFile.range[rangs].value := ads.fields[i - xs + 2].AsString;
end;
ads.Next;
frmProGress.cxPsbpsb.Position :=
frmProGress.cxPsbpsb.Position + progressstep;
frmProGress.lbl1.Caption := IntToStr(j) + '/' + IntToStr(MaxRow);
Application.ProcessMessages;
end;
frmProGress.Show;
MaxRow := ads.RecordCount;
frmProGress.lbl1.Caption := '0/' + IntToStr(MaxRow);
progressstep := 100 / MaxRow;
frmProGress.cxPsbpsb.Position := 0;
ads.First;
xj := ys + 1;
for j := xj to ads.RecordCount + ys do
begin
for i := xs to ads.fieldcount - 3 + xs do
begin
rangs := crs[i] + inttostr(j);
PackListToExcelFile.range[rangs].Font.bold := False;
PackListToExcelFile.range[rangs].font.size := fs;
PackListToExcelFile.range[rangs].Font.Name := 'Courier New';
PackListToExcelFile.range[rangs].value := ads.fields[i - xs + 2].AsString;
end;
ads.Next;
frmProGress.cxPsbpsb.Position :=
frmProGress.cxPsbpsb.Position + progressstep;
frmProGress.lbl1.Caption := IntToStr(j) + '/' + IntToStr(MaxRow);
Application.ProcessMessages;
end;
解决方案 »
- 请教(50分)F4的ascII码是多少如何判断当键盘按下F4,分不够再加
- 关于动态生成控件的两个问题(up有分!)
- (小虾急问)如何让主进程知道它所调用的子进程(exe文件)已经运行结束?
- 夜猫,问你一个问题
- AdapterGrid字体设置的问题
- 如何做判断?关于treeview的!!!
- 急!!!!!!!!!!!!!!在线等@!
- //想在DBGRID1的ZH中在DBGRID2中显示出其数据,不知道怎么做出这效果
- D5的升级包序列号?应该有两个,还有一个是ADO的!
- 虚心请教!如何取得另一程序的窗体的句柄?
- 怎样列出Access库中所有表的名称?*分够多了*
- 初用TCLIENTDATASET,很无奈
最好的方法是
使用ADOConncetion像数据库一样访问Excel表,往表中写数据。
PackListToExcelFile.range[rangs].font.size := fs;
PackListToExcelFile.range[rangs].Font.Name := 'Courier New';
PackListToExcelFile.range[rangs].value := ads.fields[i - xs + 2].AsString;
这段代码这样跑是不行的,前面三行完全可以拿到循环外面来,等你把数据写完了再统一进行排版
2。用PackListToExcelFile。range('a1').copyfromrecordset rs 跟快
3。
OPENROWSET(‘MSDASQL.1‘, ‘driver=Microsoft Excel Driver (*.xls);DBQ=e:tempbook2.xls‘,‘select * from [sheet1$]‘)==============================================================
SELECT 故障归类,故障代码,故障描述 INTO code FROM
OPENROWSET(‘MSDASQL.1‘, ‘driver=Microsoft Excel Driver (*.xls);DBQ=c:\code.xls‘,‘select 故障归类,故障代码,故障描述 from [sheet1$]‘)
第一种方法可能会导致5列数据只导出3列,把*写成所有具体的列名就可以避免这个问题拉!
Excel联接ADO串
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp\a.xls;Extended Properties="Excel 8.0;HDR=Yes;";Persist Security Info=False
利用剪贴板,速度很快!适合装有Excel的机器
USES Clipbrd,ComObj;procedure TForm1.Button1Click(Sender: TObject);
var
str:string;
i:Integer;
excelapp,sheet:Variant;
begin
// lbl2.Caption:=DateTimeToStr(Now);
str:='';
dbgrd1.DataSource.DataSet.DisableControls;
for i:=0 to dbgrd1.DataSource.DataSet.FieldCount-1 do
str:=str+dbgrd1.DataSource.DataSet.fields[i].DisplayLabel+char(9);
str:=str+#13;
dbgrd1.DataSource.DataSet.First;
while not(dbgrd1.DataSource.DataSet.eof) do begin
for i:=0 to dbgrd1.DataSource.DataSet.FieldCount-1 do
str:=str+dbgrd1.DataSource.DataSet.Fields[i].AsString+char(9);
str:=str+#13;
dbgrd1.DataSource.DataSet.next; lbl1.Caption:=IntToStr(dbgrd1.DataSource.DataSet.RecNo);
Application.ProcessMessages;
end;//end while dbgrd1.DataSource.DataSet.EnableControls; clipboard.Clear;
Clipboard.Open;
Clipboard.AsText:=str;
Clipboard.Close;
excelapp:=createoleobject('excel.application');
excelapp.workbooks.add(1); // excelapp.workbooks.add(-4167);
sheet:=excelapp.workbooks[1].worksheets[1];
sheet.name:='sheet1';
sheet.paste;
Clipboard.Clear;
// sheet.columns.font.Name:='宋体';
// sheet.columns.font.size:=9;
// sheet.Columns.AutoFit;
excelapp.visible:=true;
// lbl3.Caption:=DateTimeToStr(Now);end;/////////////////////////////////////////////
利用TStringList,速度很快!适合没有装Excel的机器
procedure TForm1.Button1Click(Sender: TObject);
var
s:TStringList;
str:string;
i:Integer;
begin
// lbl1.Caption:=DateTimeToStr(Now);
str:='';
dbgrd1.DataSource.DataSet.DisableControls;
for i:=0 to dbgrd1.DataSource.DataSet.FieldCount-1 do
str:=str+dbgrd1.DataSource.DataSet.fields[i].DisplayLabel+char(9);
str:=str+#13;
dbgrd1.DataSource.DataSet.First;
while not(dbgrd1.DataSource.DataSet.eof) do begin
for i:=0 to dbgrd1.DataSource.DataSet.FieldCount-1 do
str:=str+dbgrd1.DataSource.DataSet.Fields[i].AsString+char(9); str:=str+#13;
dbgrd1.DataSource.DataSet.next;// lbl3.Caption:=IntToStr(dbgrd1.DataSource.DataSet.RecNo);
// Application.ProcessMessages; end;//end while dbgrd1.DataSource.DataSet.EnableControls;
s:=TStringList.Create;
s.Add(str);
s.SaveToFile('c:\temp.xls');//保存到c:\temp.xls
s.Free;
// lbl2.Caption:=DateTimeToStr(Now);end;
////////////////////////////////////////////////
str:=str+ tempQuery.Fields[i].FieldName+#9;
buffList.Add(str); while not TempQuery.Eof do
begin
str:='';
for i:=0 to TempQuery.FieldCount-1 do
str:=str+TempQuery.Fields[i].AsString+#9;
buffList.Add(str);
ProgressBar2.Position:=ProgressBar2.Position+1;
TempQuery.Next;
end;
buffList.SaveToFile('c:\aa.xls');不过这种方法生成的.xls文件并不是真正的excle文件,他只不过是个文本文件。
roomid=5301&typenum=1&xmlsrc=&whichpage=1