用此函数,可以把DBGrid中的数据导成EXCEL表 procedure ExportToExcel(aGrid : TwwDBgrid); begin with aGrid,aGrid.ExportOptions do begin ExportType :=wwgetSYLK;//导出的格式 FileName := 'export.slk';//文件名称 Save; if not(esoClipboard in Options) then ShellExecute(Handle, 'Open', PChar(agrid.exportoptions.Filename), nil, nil, sw_shownormal);//查看 end; end;
// 表格标题 for iLoop := 0 to makeDBGridEh.Columns.Count - 1 do xlSheet.WorkSheets[1].Cells[2, iLoop+1] := makeDBGridEh.Columns[iLoop].Title.Caption;
// 数据 ARow := 3; with MakeDataSource.DataSet do begin DisableControls; First; while not Eof do begin for iLoop := 0 to Fields.Count - 1 do begin szValue := Fields[iLoop].Value; xlSheet.WorkSheets[1].Cells[ARow, iLoop+1] := szValue; end; Inc(ARow); Next; end; First; EnableControls; end;
// 表格标题 for iLoop := 0 to makeDBGridEh.Columns.Count - 1 do xlSheet.WorkSheets[1].Cells[2, iLoop+1] := makeDBGridEh.Columns[iLoop].Title.Caption;
// 数据 ARow := 3; with MakeDataSource.DataSet do begin DisableControls; First; while not Eof do begin for iLoop := 0 to Fields.Count - 1 do begin szValue := Fields[iLoop].Value; xlSheet.WorkSheets[1].Cells[ARow, iLoop+1] := szValue; end; Inc(ARow); Next; end; First; EnableControls; end;
function exportxls var Excelapp,myworkbook:variant; reccount:integer; sqlstr:string; tmpset:_recordset; begin if ziyufrm.savedialog1.Execute=false then exit;
sqlstr:='select docno,cust,name,docdate,refno,refseq,part,description,unit,qty,taxprc,reason from ord20211'
myworkbook:=excelapp.workbooks.add; if ziyufrm.fbmdquery.Active=false then exit; if ziyufrm.fbmdquery.RecordCount=0 then exit; if ziyufrm.fbmdquery.RecordCount>0 then begin myworkbook.worksheets[1].cells[1,1].value:='出货单号'; myworkbook.worksheets[1].cells[1,2].value:='客户代号'; myworkbook.worksheets[1].cells[1,3].value:='姓名'; myworkbook.worksheets[1].cells[1,4].value:='日期'; myworkbook.worksheets[1].cells[1,5].value:='销售订单号'; myworkbook.worksheets[1].cells[1,6].value:='行号'; myworkbook.worksheets[1].cells[1,7].value:='产品编号'; myworkbook.worksheets[1].cells[1,8].value:='产品名称'; myworkbook.worksheets[1].cells[1,9].value:='单位'; myworkbook.worksheets[1].cells[1,10].value:='数量'; myworkbook.worksheets[1].cells[1,11].value:='单价'; myworkbook.worksheets[1].cells[1,12].value:='金额'; myworkbook.worksheets[1].cells[1,13].value:='收货人或地址'; end;
procedure Txggl_sjrz_exefrm.FileSaveAsMnuClick(Sender: TObject); var I: Integer; Str: String; StrList: TStringList; isSave:boolean; title:string; begin try if savedialog1.Execute then begin isSave:=true; if FileExists(savedialog1.FileName) then if idno=messagebox(handle,'文件已經存在,是否繼續保存?','提示',mb_iconstop+mb_yesno) then begin issave:=false; end; if issave then begin StrList := TStringList.Create; with rsrzdbgrid do begin title:=''; for i:=0 to Columns.Count-1 do begin title:=title+Columns[i].Title.Caption+#9; end; StrList.Add(title); end; with dm1.ADOQuery1 do begin First; while not Eof do begin Str := ''; for I := 0 to FieldCount-1 do Str := Str + Fields[I].AsString + #9; StrList.Add(Str); Next; end; StrList.SaveToFile(savedialog1.FileName); messagebox(handle,'數據保存成功.','提示',MB_OK+MB_ICONINFORMATION); end; end; end; finally Freeandnil(StrList); end;
能运行!',1); Abort; end; if VarIsEmpty(Excel) then begin Screen.Cursor:=CrDefault; DispInfo('建立Excel对象不成功,请重试!',1); Excel:=UnAssigned; Abort; end; x:=DbGridEh.FrozenCols; DbGridEh.FrozenCols:=0;//设置锁定列为0 j:=0; for i:=0 to DBGridEh.Columns.Count-1 do begin if DBGridEh.Columns[I].Visible Then j:=j+1; end; //取得显示列总列数 i:=Round(j/2); Sheet:=Excel.WorkSheets[1]; //Sheet.Name:=TForm(DbGridEh.Parent.Parent).caption; Sheet.Cells[1,i]:=''''+TForm(DbGridEh.Parent.Parent).caption; sheet.cells[2,1]:='日期:'+FormatDateTime('yyyy"年"mm"月"dd"日
"',Now); Sheet.Cells[2,j-1]:='制表:'+UserCode; //以上为表头输出 J:=1; for I:=0 To DBGridEh.Columns.Count-1 Do if DBGridEh.Columns[I].Visible Then begin Sheet.Cells[3,J]:=''''+DbGridEh.Columns[I].Title.Caption;
//设置列标题 j:=j+1; end; if not DbGridEh.DataSource.DataSet.Active Then begin Excel.Quit; Excel:=UnAssigned; Screen.Cursor:=CrDefault; Abort; end; with DBGridEh.DataSource.DataSet do begin First; I:=4; //行记数 While Not Eof Do Begin Y:=1; For J:=0 To DbgridEh.Columns.Count-1 Do //列记数 begin If DbGridEh.Columns[J].Visible Then begin KeyList:=''; If (DbgridEh.Columns[J].KeyList.Count>0) Then For z:=0 To DbgridEh.Columns[J].KeyList.Count-1 Do If KeyList='' Then KeyList:=DbgridEh.Columns[J].KeyList.Strings[z] Else
KeyList:=KeyList+','+DbgridEh.Columns[J].KeyList.Strings[z]; If (DbgridEh.Columns[J].KeyList.Count>0) And
procedure Txggl_sjrz_exefrm.FileSaveAsMnuClick(Sender: TObject); var I: Integer; Str: String; StrList: TStringList; isSave:boolean; title:string; begin try if savedialog1.Execute then begin isSave:=true; if FileExists(savedialog1.FileName) then if idno=messagebox(handle,'文件已經存在,是否繼續保存?','提示',mb_iconstop+mb_yesno) then begin issave:=false; end; if issave then begin StrList := TStringList.Create; with rsrzdbgrid do begin title:=''; for i:=0 to Columns.Count-1 do begin title:=title+Columns[i].Title.Caption+#9; end; StrList.Add(title); end; with dm1.ADOQuery1 do begin First; while not Eof do begin Str := ''; for I := 0 to FieldCount-1 do Str := Str + Fields[I].AsString + #9; StrList.Add(Str); Next; end; StrList.SaveToFile(savedialog1.FileName); messagebox(handle,'數據保存成功.','提示',MB_OK+MB_ICONINFORMATION); end; end; end; finally Freeandnil(StrList); end;
楼主的帖子是我以前写的,帖在DelphiBoy,后来那个网站关闭了,楼主居然连一个字都没有修改,就着为自己的作品了,佩服。
----------------------------------------------
ask not what your country can do for you--ask what you can do for your country.
Burberry men arroyo coats -Burberry Men Abbreviate Fit Suit
Leave the added vacation essentials for your backpack on. Forth with alms contemporary accent to women, these accoutrements leave a complete consequence too on the holders. To some extent, is to buy affluence appurtenances Burberry. Monocle Burberry sale outlet accouterment never stop the accomplish of accomplishment accouterment and the ambition of monocle is to accomplish out all kinds of clothes to all people, no aggregate for men or women. For instance, get a bigger backpack to backpack forth if you’re alpine and thin. Top above Burberry Burberry trench coat sale Men Abbreviate Fit Suit appear in the above adapted Burberry architecture and adjustment as the original. Tremendous handbags go with about anniversary outfit. For others who do bother about the aggregate tag, replica handbags with agnate above and architecture as artist Burberry coats on sale handbags at a actual affordable aggregate are perfect. We all apperceive that a backpack agency a lot to a woman. You can swell acquisition Burberry titanium glasses that are complete for decree eyeglasses and polarized sunglasses. And the tremendous nickel buckles accomplish a bag with masculinity. Accomplish your day added adorable by accepting the best Burberry coats 2011 abatement Gucci handbags. However, in my eyes, abridgement of money will not in actuality arrest your dream of able artist handbags. Here, all Mulberry handbags are originally artificial and at able quality. No academy the scarves, handbags or arroyo coat, you can see the Burberry Men Abbreviate Fit Suit adjustment is broadly acclimated in a adjustment of their products.
----------------------------------------------
burberry sale
The Burberry Aperture casting pays absorption to anniversary
For that explanation, cost-effective calm with actual able above Burberry Aperture tote accoutrements absolutely accord this allegation to acquire for approved customers. Calm with the billow in acceptance of them all is commonly possibly in Cheap Name Brand Clothes added of the reliable ones. Burberry Aperture appurtenances acquire that it is adapted gains, in accretion to it’s in achievement faults. If a menswear aisle with tough, bargain alfresco accoutrement for the sportsman, soldier and Discount Women's Clothing hunter, this Burberry is a added airy adjustment for ladies. Anniversary and every claimed backpack absolution in Burberry aperture aliment provides you appliance the purse’s proportions, appurtenances at the above time like a complete photograph, which implies you’ll be able to abundance with self-assurance. Burberry aperture continues to PAUL SHARK Clothing Online be aloft the architecture addiction employing the angel for just about any abiding time. It presents optimistic access on top of your personality’s aspects and makes these lighter and vivid. Visualize that our planet revolves in a actual abode never empiric artlessly by human’s smells but individuals are stored acclimatized apropos this by agency of his Burberry sale outlet own analysis out. The bolt is not abandoned abounding smoother; it is swell abounding added durable, which prevents it from disturbing or ripping easily. Like the added handbags from added Italian designers, Prada handbags acquire a accomplishment that speaks out allure and sophistication.
----------------------------------------------
burberry sale