报表制作技巧(一)

boymaster boymaster 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
格式化整数输出
  比较大的数字在输出时会显得不易阅读,在Delphi中显示带分节号的数字是相当简单的一件事,如下即可:xxxxx.caption:ΚFormatFloat(′#′,524667500)。

当前打印机的分辨率

Windows下的打印分辨对打印程序有着至关重要的作用,如果你想知道打印机的分辨率,请在程序中加入一行:ShowMessage(′水平分辨率′+inttostr(GetDeviceCaps(printerHandle,LOGPIXELSX))+chr(13)+′垂直分辨率:′+inttostr(GetDeviceCaps(printerHandle,LOGPIXELSY)));结果就一目了然了。

将结果直接送到打印机

Delphi提供了两种打印方式:一是将结果输送到Form,再调用Form的print方法将结果输送到打印机,二是将结果直接输送到打印机。如果你采用第一种方式,则无论你怎样调整Form的PrintScal属性,打印出来的东西也不会让你满意。因此建议采用第二种方式。



报表制作技巧(二)
整理编辑:China ASP

尽量不要使用AssignPrn

尽管AssignPrn简化了文本打印操作,使输出到打印机像输出到文件一样简单。但简单带来的是一系列的不方便:你无法知道当前打印的行数,无法准确控制行距,无法灵活改变字体字形等等。还是用打印机的Canvas属性进行打印吧。

用打印机的点数做度量单位

如果想让打印程序在任何打印机上都能正常地打印,你就必须改变你的度量单位。如果采用固定的度量,不同分辨率的打印效果是不同的。举例来讲:printerCanvasrectangle(0,0,360,720)在360×360的佳能4200SP上能打出一个1英寸宽、2英寸高的矩形,但在600×600的惠普6L上只能打出06英寸宽、12英寸高的矩形。使用打印机的点数做为度量单位是一个明智的选择。具体做法如下:VarPointX,PointY:integer;PointX:=GetDeviceCaps(printerHandle,LOGPIXELSX);PointY:=GetDeviceCaps(printerHandle,LOGPIXELSX);printerCanvasrectangle(0,0,PointX*1,PointY*2)这样,无论你使用什么样的打印机,都能得到一个1英寸宽、2英寸高的矩形。

添加打印程序单元

尽管Delphi在生成窗体时会自动在USES部分加入许多程序单元,但打印程序单元(Printers)却不在之列,要想使打印机正常工作和程序不出错,你还是老老实实手工给它加上吧。

报表制作技巧(三)
整理编辑:China ASP

任意打印

  有时我们要打印任意排列的表或往已经印好的登记表上对号入座写上数据时,可以新建一个窗体(假设为Form1),再把Form1的BorderStyle设为bsNone、AutoScroll设为True,接下来再创建一个新窗体(假设为Form2),再建个按钮Button1,编写代码:
procedure TForm2.Button1Click(Sender: TObject);
begin
Form1.Width :=900;
Form1.Height :=800;
Form1.Print;
end;
  接下来你在Form1上对应的位置写上数据,运行后按Button1就会一五一十的打印下来了。

打印机的分辨率问题?
Printer Resolution ?
问:
I want to know, wich way I have to program, so every print is equal. No
matter what resolution
of the printer (300 or 600 dpi).
Since now I program: TextOut(DC, 150, 150...) on a 300 dpi printer. But on
600 dpi, everything
looks a bit strange, (small).

What Objects can I use to print corectly??
答:
I get the printer resolution (and unprintable are if desired) and
then specify coordinates using decimal inches * resulution e.g.

x = trunc(1.5 * ResX) at 300 dpi will begin at 360 * 1.5 or 540 pixels.

Get Resolution and unprintable
ResX := GetDeviceCaps(ACanvas.Handle,LOGPIXELSX);
ResY := GetDeviceCaps(ACanvas.Handle,LOGPIXELSY);
pOffsetX := GetDeviceCaps(ACanvas.Handle,PHYSICALOFFSETX);
pOffsetY := GetDeviceCaps(ACanvas.Handle,PHYSICALOFFSETY);

print something

Printer.Canvas.TextOut(trunc(1.5 * ResX)-pOffsetX,
trunc(2.5 * ResY)-pOffsetY,'Hello');

This is nice when prp元件上点出右键菜单,选Report Setting项,将弹出一个设置窗口,将
Margins项中的Number of columns项设为你想在一行中显示的记录数,然后你会发现。。。:)


在打印或打印预览前如何获取报表页数
整理编辑:China ASP

我们有时需要在打印前获取报表的打印页数, 比如我们需要在页眉或页脚中打印“共 xx 页 第 xx 页”,那如何实现呢? QuickRep生成Report之前,我们是无法得知报表页数的,而QuickReport是在打印或打印预览时才生成报表,换言之我们只有在 打印或打印预览前先将报表生成一次才能获取打印页数.生成报表的方法是 Prepare。参考以下的例子:
...
var nPageCount:integer;
begin
  {...}
   QuickRep1.Prepare;
   nPageCount:=QuickRep1.QRPrinter.PageCount;
   QuickRep1.QRPrinter.Free;
   QuickRep1.QRPrinter:=nil;
   {在此修改QuickRep1,实现在页眉或页脚中打印“共 xx 页 第 xx 页” ... }
   QuickRep1.PreView;
   {...}
End;
...全文

相关推荐

Objective C Pocket Reference.rar

Objective C Pocket Reference.rar

飞哥

iPhone.rar_iPhone/iOS_Objective-C_

iPhone开发必备资料,齐全,是开发必不可缺的资料

pudn01

Kindle Computer Science other.rar

计算机科学类图书打包,mobi格式。 Apress Beginning 3D Game Development with Unity.mobi Apress Beginning BlackBerry 7 Development.mobi NoStarch IDA Pro Book 2nd.mobi OReilly PDF Explained.mobi OReilly Programming Scala.mobi Social Engineering.mobi Wrox Beginning Lua Programming.mobi Android\Android Programming Tutorials.mobi Android\Apress Android Recipes.mobi Android\Apress Pro Android Python with SL4A.mobi Android\OReilly Application Security for the Android Platform.mobi Android\Oreilly Learning Android.mobi Android\The Busy Coders Guide to Advanced Android Development.mobi Android\The Busy Coders Guide to Android Development.mobi Android\Wiley App Inventor for Android.mobi Apple\101024Apple Pro Training Aperture 3.mobi Apple\101102Apple Pro Training Series AppleScript 1-2-3.mobi Apple\Apple Pro Training Aperture 3 - Organize Perfect and Showcase Your Photos.mobi Apple\Apple Pro Training Series AppleScript 1-2-3.mobi Database\Apress Access 2010 Development.mobi Database\Apress Expert Oracle Exadata.mobi Database\Apress Expert Oracle GoldenGate.mobi Database\Apress Expert PL SQL Practices for Oracle Developers and DBAs.mobi Database\Apress Oracle PLSQL Recipes - A Problem-Solution Approach.mobi Database\Apress Pro Oracle Database 11g Administration.mobi Database\Apress Troubleshooting Oracle Performance.mobi Database\Oracle Internals - Tips Tricks and Techniques for DBAs.mobi Database\OReilly High Performance MySQL.mobi Database\OReilly SQL and Relational Theory 2nd.mobi Database\OReilly SQL Cookbook.mobi Database\OReilly SQL Pocket Guide 3rd.mobi Database\Pragmatic SQL Antipatterns Avoiding the Pitfalls of Database Programming.mobi Flash\FriendsofED AdvancED ActionScript 3.0 Design Patterns.mobi Flash\OReilly Automating ActionScript Projects with Eclipse and Ant.mobi Flash\OReilly Quick Guide to Flash Catalyst.mobi iOS_Mac\Addison Learning Cocos2D.mobi iOS_Mac\Addison Programming in Objective-C 3rd.mobi iOS_Mac\Apple Pro Training Aperture 3 - Organize Perfect and Showcase Your Photos.mobi iOS_Mac\Apple Pro Training Series AppleScript 1-2-3.mobi iOS_Mac\Apress Beginning OSX Lion Apps Development.mobi iOS_Mac\Apress Learn cocos2d Game Development with iOS 5.mobi iOS_Mac\Apress Migrating to iPhone and iPad for dotNET Developers.mobi iOS_Mac\Apress Pro iOS Apps Performance Optimization.mobi iOS_Mac\iPhone Programming The Big Nerd Ranch Guide.mobi iOS_Mac\OReilly Basic Sensors in iOS.mobi iOS_Mac\OReilly Developing Enterprise iOS Applications.mobi iOS_Mac\OReilly iOS 4 Programming Cookbook.mobi iOS_Mac\OReilly Mac OS X for Unix Geeks Leopard 4th.mobi iOS_Mac\Pragmatic iOS Recipes.mobi iOS_Mac\Pragmatic Mac Kung Fu.mobi iOS_Mac\Wrox Beginning iOS Game Development.mobi iOS_Mac\Wrox Building Applications for Mac App Store.mobi Lisp\NoStarch Land of Lisp - Learn to Program One Game at a Time.mobi Perl\OReilly Learning Perl 6th.mobi Perl\OReilly Perl Pocket Reference.5th.mobi PHP\OReilly Building on SugarCRM.mobi PHP\OReilly Web Database Applications with PHP and MySQL 2nd.mobi PHP\Packt WordPress 3 Plugin Development Essentials.mobi Python\Addison Python Standard Library by Example, the Developers Library.mobi Python\Addison Python Web Development with Django.mobi Python\Apress The Definitive Guide to Django - Web Development Done Right.mobi Python\OReilly Learning Python 4th.mobi Python\OReilly MongoDB and Python.mobi Python\OReilly Programming Python 3rd.mobi Python\OReilly Python and AWS Cookbook.mobi Python\OReilly Python for Unix and Linux System Administration.mobi Python\OReilly Social Network Analysis for Startups.mobi Python\Packt Django 1.1 Testing and Debugging.mobi R\NoStarch The Art of R Programming.mobi R\OReilly Data Mashups in R.mobi R\OReilly Machine Learning for Email.mobi R\OReilly Parallel R.mobi SAP\McGraw SAP Project System Handbook.mobi SAP\OReilly Microsoft .NET and SAP (Pro-Developer).mobi SAP\Sams Teach Yourself SAP in 24 Hours 4th.mobi StackOverflowE-Books\stack_overflow_ajax.mobi StackOverflowE-Books\stack_overflow_android.mobi StackOverflowE-Books\stack_overflow_asp.net.mobi StackOverflowE-Books\stack_overflow_c.mobi StackOverflowE-Books\stack_overflow_clojure.mobi StackOverflowE-Books\stack_overflow_cocoa.mobi StackOverflowE-Books\stack_overflow_css.mobi StackOverflowE-Books\stack_overflow_database.mobi StackOverflowE-Books\stack_overflow_delphi.mobi StackOverflowE-Books\stack_overflow_django.mobi StackOverflowE-Books\stack_overflow_drupal.mobi StackOverflowE-Books\stack_overflow_erlang.mobi StackOverflowE-Books\stack_overflow_f#.mobi StackOverflowE-Books\stack_overflow_flash.mobi StackOverflowE-Books\stack_overflow_flex.mobi StackOverflowE-Books\stack_overflow_git.mobi StackOverflowE-Books\stack_overflow_haskell.mobi StackOverflowE-Books\stack_overflow_html.mobi StackOverflowE-Books\stack_overflow_html5.mobi StackOverflowE-Books\stack_overflow_iphone.mobi StackOverflowE-Books\stack_overflow_jquery.mobi StackOverflowE-Books\stack_overflow_linq.mobi StackOverflowE-Books\stack_overflow_linux.mobi 。。。

osketch1

fengmian123

fengmian123

CiYuanShuos

QYR-18900-2026-2032全球与中国智能旋转导向钻井系统市场现状及未来发展趋势 Sample-shijunzhong.docx

QYR-18900-2026-2032全球与中国智能旋转导向钻井系统市场现状及未来发展趋势 Sample-shijunzhong.docx

qyresearch报告
评论 1
收藏 已收藏
分享
返回顶部
boymaster
IBM开发者 205 成员 2,480 内容