哪位帮我看看这段Dbgrideh导出excel代码,应该如何才能按照原Dbgrideh小数位在excel显示? ( 积分: 50 )

  • 主题发起人 主题发起人 fjharmer
  • 开始时间 开始时间
F

fjharmer

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure&nbsp;dc_excel(DBG:&nbsp;TDbgrideh);<br>var<br>&nbsp;&nbsp;I:&nbsp;Integer;<br>&nbsp;&nbsp;ExcelApp:&nbsp;variant;<br>&nbsp;&nbsp;SourceDataSet:&nbsp;tdataset;<br>begin<br>&nbsp;&nbsp;SourceDataSet&nbsp;:=&nbsp;Tdataset(DBG.DataSource.DataSet);<br>&nbsp;&nbsp;if&nbsp;(SourceDataSet.IsEmpty)&nbsp;or&nbsp;(not&nbsp;SourceDataSet.active)&nbsp;or<br>&nbsp;&nbsp;&nbsp;&nbsp;(DBG.VisibleColumns.Count&nbsp;=&nbsp;0)&nbsp;then<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;application.MessageBox(pchar('无法导出数据到Excel,可能是系统中未安装Excel。'),&nbsp;'导出错误',&nbsp;mb_ok&nbsp;+&nbsp;mb_iconstop);<br>&nbsp;&nbsp;&nbsp;&nbsp;Abort;<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;//<br>&nbsp;&nbsp;for&nbsp;I&nbsp;:=&nbsp;1&nbsp;to&nbsp;100&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;not&nbsp;IsFileInUse(main.one_path&nbsp;+&nbsp;'/file'&nbsp;+&nbsp;Inttostr(I)&nbsp;+&nbsp;'.xls')&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SaveDBGridEhToExportFile(TDBGridEhExportAsXLSTile,&nbsp;DBG,&nbsp;main.one_path&nbsp;+<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'/file'&nbsp;+Inttostr(I)&nbsp;+&nbsp;'.xls',&nbsp;True);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExcelApp&nbsp;:=&nbsp;CreateOleObject('Excel.Application');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExcelApp.visible&nbsp;:=&nbsp;true;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExcelApp.WorkBooks.Open(main.one_path&nbsp;+&nbsp;'/file'&nbsp;+&nbsp;Inttostr(I)&nbsp;+&nbsp;'.xls');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit;<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;end;<br>end;
 
简单解决方法就是做个模版xls,然后向模版里写数据即可
 
估计要动手修改DBGridEhImpExp&nbsp;中的&nbsp;procedure&nbsp;WriteFloatCell(const&nbsp;AValue:&nbsp;Double);,就是因为这个不爽,我自己另写procedure&nbsp;导出到Excel,当然速度比<br>SaveDBGridEhToExportFile慢很多。
 
后退
顶部