如何决解导出数据到excel,帐号变成科学记数法? ( 积分: 50 )

  • 主题发起人 主题发起人 txzhf
  • 开始时间 开始时间
T

txzhf

Unregistered / Unconfirmed
GUEST, unregistred user!
源码如下:<br>&nbsp;SaveFn:String;<br>&nbsp;&nbsp;SaveDialog1:&nbsp;TSaveDialog;<br>&nbsp;&nbsp;ExcelApplication1:&nbsp;TExcelApplication;<br>&nbsp;&nbsp;ExcelWorksheet1:&nbsp;TExcelWorksheet;<br>&nbsp;&nbsp;ExcelWorkbook1:&nbsp;TExcelWorkbook;<br>&nbsp;&nbsp;i,row,column&nbsp;:integer;<br>&nbsp;&nbsp;xlsheet,range:&nbsp;Variant;<br>begin<br>&nbsp;SaveDialog1:=TSaveDialog.Create(Application.Owner);<br>&nbsp;SaveDialog1.Filter:='*.Xls';<br>&nbsp;if&nbsp;Not&nbsp;SaveDialog1.Execute&nbsp;&nbsp;then&nbsp;SaveDialog1.Execute&nbsp;;<br>&nbsp;SaveFn:=SaveDialog1.FileName&nbsp;;<br>&nbsp;if&nbsp;SaveFn=''&nbsp;then<br>&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messagedlg('请输入文件名!',mtinformation,[mbok],0);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;abort&nbsp;;<br>&nbsp;end;<br>&nbsp;ExcelApplication1:=TExcelApplication.Create(Application.Owner);<br>&nbsp;ExcelWorksheet1:=TExcelWorksheet.Create(Application.Owner&nbsp;);<br>&nbsp;ExcelWorkbook1:=TExcelWorkbook.Create(Application.Owner&nbsp;);<br>&nbsp;try<br>&nbsp;&nbsp;&nbsp;&nbsp;ExcelApplication1.Connect&nbsp;;<br>&nbsp;&nbsp;except<br>&nbsp;&nbsp;&nbsp;&nbsp;MessageDlg('请确定是否正确安裝Excel2003?',mterror,[mbok],0);<br>&nbsp;&nbsp;&nbsp;&nbsp;abort;<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;ExcelApplication1.Visible[0]:=False;<br><br>&nbsp;&nbsp;ExcelApplication1.Caption:='营业收费系统导出数据';<br>&nbsp;&nbsp;ExcelApplication1.Workbooks.Add(Null,0);<br>&nbsp;&nbsp;ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);<br>&nbsp;&nbsp;ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1]&nbsp;as&nbsp;_worksheet);<br><br>&nbsp;&nbsp;qry1.First&nbsp;;<br>&nbsp;&nbsp;for&nbsp;i:=1&nbsp;to&nbsp;qry1.FieldCount&nbsp;&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExcelWorksheet1.Cells.Item[1,i]:=qry1.Fields[i-1].DisplayLabel&nbsp;;<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;row:=2;<br>&nbsp;&nbsp;while&nbsp;not&nbsp;qry1.Eof&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;column:=1;<br>&nbsp;&nbsp;&nbsp;for&nbsp;i:=1&nbsp;to&nbsp;qry1.FieldCount&nbsp;do<br>&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExcelWorksheet1.Cells.Item[row,column]:=qry1.Fields[i-1].AsString&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;column:=column+1;<br>&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;row:=row+1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qry1.Next&nbsp;;<br>&nbsp;&nbsp;end;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;//ExcelApplication1.Visible[0]:=True;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xlsheet:=ExcelWorkbook1.ActiveSheet&nbsp;&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xlsheet.PageSetup.PrintGridLines&nbsp;:=&nbsp;True&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;ExcelApplication1.ActiveWorkBook.Saved&nbsp;:=&nbsp;True;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;range:=xlsheet.range[xlsheet.cells[1,1],xlsheet.cells[qry1.RecordCount+1&nbsp;,qry1.FieldCount]];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;range.font.size:=12;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;range.HorizontalAlignment:=xlGeneral;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;range.VerticalAlignment:=xlGeneral;<br>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;range.AutoFit;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;range.Borders[1].LineStyle:=1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;range.Borders[2].LineStyle:=1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;range.Borders[3].LineStyle:=1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;range.Borders[4].LineStyle:=1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExcelWorkBook1.SaveCopyAs(SaveFn+'.XLS');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;excelWorkbook1.Close;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;excelapplication1.Disconnect;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;excelapplication1.Free;
 
转换类型问题,要设置excel&nbsp;单元为文本类型就好了...
 
[red]eclApp.Cells.Item[i,4].numberformat:='@';[/red]<br>eclApp.Cells(i,4):=query1.FieldByName('邮编').asstring;
 
问题已解决,谢谢你guth
 
后退
顶部