打印问题(50分)

  • 主题发起人 主题发起人 jiangxidna
  • 开始时间 开始时间
J

jiangxidna

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在用delphi2007编程,数据库用的是sql server。现在我想实现打印功能 。用了以前用的一种方法(delphi7+oracle)来实现,出现错误。这是代码:<br>procedure TfrmTowerPullStatistics.sBtnPrintClick(Sender: TObject);<br>var<br>&nbsp; Sheet,ExcelApp : variant;<br>&nbsp; i,j : integer;<br>begin<br>&nbsp; inherited;<br>ExcelApp:=CreateOleObject('Excel.Application');<br>&nbsp; ExcelApp.Visible:=TRUE;<br>&nbsp; ExcelApp.WorkBooks.Add[GAppPath+'/Xls/塔杆受力监测数据.xlt'];<br>&nbsp; Sheet:=ExcelApp.WorkBooks[1].WorkSheets['Sheet1'];<br>&nbsp; ExcelApp.DisplayAlerts:=FALSE;<br>&nbsp; IF EPDM.PowerDM.Query3.State =dsBrowse &nbsp;Then<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; EPDM.PowerDM.Query3.First;<br>&nbsp; &nbsp; &nbsp; with EPDM.PowerDM.Query3 do<br>&nbsp; &nbsp; &nbsp; while not eof Do<br>&nbsp; &nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For i:=0 to RecordCount-1 do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sheet.Cells[i+3,1] :=FieldByName('xlmc').asstring;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sheet.Cells[i+3,2] :=FieldByName('btgh').asstring;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sheet.Cells[i+3,3] :=FieldByName('byqckdlax').asstring;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sheet.Cells[i+3,4] :=FieldByName('byqckdlbx').asstring;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sheet.Cells[i+3,5] :=FieldByName('byqckdlcx').asstring;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sheet.Cells[i+3,6] :=FieldByName('sxbphl').asstring;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; next;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp;MessageBoxes('没有数据可以打印');<br>&nbsp; &nbsp; &nbsp;exit;<br>&nbsp; &nbsp; end;<br>end;<br><br>end.
 
什么错误?你以为大家都闲着没事专门给你编译代码?还装个Oracle、Office给你做试验??
 
呵呵 是我没说明白,man8888兄弟说的对,谢谢了<br>这样的:我发现里面的Sheet:=ExcelApp.WorkBooks[1].WorkSheets['Sheet1'];中WorkBooks有错误。运行到这报无效索引的错,因为对这条语句不太明白,所以这个错无从下手。希望man8888兄弟有空指导一下。呵呵
 
Sheet := eclApp.workBooks[1].WorkSheets[1];<br>&nbsp; &nbsp;试试看
 
最后终于查出来了 &nbsp;是我的excel里面与worksheets的内容不一致导致的<br>谢谢诸位了
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部