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;
解决方案 »
- 资源管理器中文件的粘贴(从剪切板)、删除如何实现
- 有很多程序,表格中的下拉列表用鼠标点时显示的是代码,鼠标移开后,却显示为名称。
- 求一文字识别算法,希望在1秒内识别出包含5个数字的图片
- 如何把delphi中的不可见控件制作成ocx或者dll,与其他开发环境共享
- 散分喽,如何利用idhttp、多线程同时下载多个文件?
- 请教个线程问题,标题说不清楚,详见内容。100分!
- 未来的浏览器会不会是3D的.
- 请各位高手指点!!!关于排课系统
- 如何实现非报表打印输出,例如打印小票单据,请问用什么语句可以直接输出到打印机??
- 一个关于D6的问题
- 怎样列出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