富翁帮忙拉 -》怎样实现票据打印(27分)

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

thomashukaidi

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样实现四联单或商业发票的打印
 
用reportmachine套打
 
就是做套打程序我也不会的
 
直接使用Printers单元对打印机操作,注意事项只有打印机尺度跟屏幕尺度的转换。
下面给你的代码是对EMS进行打印的,今年刚写的。
DFM:
object FormMain: TFormMain
Left = 185
Top = 96
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle
Caption = 'Ems Printer'
ClientHeight = 463
ClientWidth = 624
Color = clBtnFace
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 12
object ButtonPrint: TButton
Left = 476
Top = 248
Width = 75
Height = 25
Caption = '打印'
TabOrder = 3
OnClick = ButtonPrintClick
end
object ButtonExit: TButton
Left = 476
Top = 371
Width = 75
Height = 25
Caption = '退出'
TabOrder = 5
OnClick = ButtonExitClick
end
object GroupBox2: TGroupBox
Left = 17
Top = 225
Width = 356
Height = 232
Caption = '收件人及说明'
TabOrder = 1
object Label6: TLabel
Left = 12
Top = 19
Width = 36
Height = 12
Caption = '电话:'
end
object Label7: TLabel
Left = 12
Top = 52
Width = 60
Height = 12
Caption = '邮政编码:'
end
object Label8: TLabel
Left = 12
Top = 86
Width = 72
Height = 12
Caption = '收件人名址:'
end
object Label9: TLabel
Left = 12
Top = 140
Width = 60
Height = 12
Caption = '内件说明:'
end
object Label13: TLabel
Left = 12
Top = 188
Width = 72
Height = 12
Caption = '交寄人签名:'
end
object Label14: TLabel
Left = 172
Top = 188
Width = 72
Height = 12
Caption = '经办人签名:'
end
object MemoAddressTo: TMemo
Left = 92
Top = 83
Width = 241
Height = 45
Alignment = taCenter
TabOrder = 2
end
object EditTelTo: TEdit
Left = 93
Top = 15
Width = 121
Height = 20
TabOrder = 0
OnKeyPress = EditTabKeyPress
end
object EditZipTo: TEdit
Left = 93
Top = 49
Width = 77
Height = 20
MaxLength = 6
TabOrder = 1
OnKeyPress = EditTabKeyPress
end
object CheckBox1: TCheckBox
Left = 16
Top = 207
Width = 97
Height = 17
Caption = '信函'
TabOrder = 5
end
object CheckBox2: TCheckBox
Left = 130
Top = 207
Width = 97
Height = 17
Caption = '文件'
TabOrder = 6
end
object CheckBox3: TCheckBox
Left = 244
Top = 207
Width = 97
Height = 17
Caption = '物品'
TabOrder = 7
end
object EditName1: TEdit
Left = 93
Top = 184
Width = 60
Height = 20
TabOrder = 3
OnKeyPress = EditTabKeyPress
end
object EditName2: TEdit
Left = 253
Top = 184
Width = 60
Height = 20
TabOrder = 4
OnKeyPress = EditTabKeyPress
end
object MemoDescript: TMemo
Left = 92
Top = 135
Width = 241
Height = 41
Alignment = taCenter
TabOrder = 8
end
end
object ButtonAbout: TButton
Left = 476
Top = 310
Width = 75
Height = 25
Caption = '关于'
Enabled = False
TabOrder = 4
end
object GroupBox3: TGroupBox
Left = 381
Top = 8
Width = 236
Height = 149
Caption = '其他'
TabOrder = 2
object Label15: TLabel
Left = 20
Top = 25
Width = 36
Height = 12
Caption = '重量:'
end
object Label20: TLabel
Left = 20
Top = 55
Width = 36
Height = 12
Caption = '资费:'
end
object Label16: TLabel
Left = 20
Top = 115
Width = 36
Height = 12
Caption = '合计:'
end
object Label17: TLabel
Left = 20
Top = 86
Width = 60
Height = 12
Caption = '其他费用:'
end
object EditWeight: TEdit
Left = 101
Top = 21
Width = 60
Height = 20
TabOrder = 0
OnKeyPress = EditTabKeyPress
end
object EditMoney: TEdit
Left = 101
Top = 51
Width = 60
Height = 20
TabOrder = 1
Text = '18.00'
OnKeyPress = EditTabKeyPress
end
object EditMoneyAll: TEdit
Left = 101
Top = 111
Width = 60
Height = 20
TabOrder = 3
Text = '20.00'
OnKeyPress = EditTabKeyPress
end
object EditMoneyOther: TEdit
Left = 101
Top = 81
Width = 60
Height = 20
TabOrder = 2
Text = '2.00'
OnKeyPress = EditTabKeyPress
end
end
object GroupBox1: TGroupBox
Left = 17
Top = 8
Width = 356
Height = 209
Caption = '寄件人'
TabOrder = 0
object Label1: TLabel
Left = 12
Top = 54
Width = 60
Height = 12
Caption = '日期时间:'
end
object Label2: TLabel
Left = 12
Top = 20
Width = 48
Height = 12
Caption = '原寄局:'
end
object Label3: TLabel
Left = 12
Top = 88
Width = 36
Height = 12
Caption = '电话:'
end
object Label4: TLabel
Left = 12
Top = 122
Width = 60
Height = 12
Caption = '邮政编码:'
end
object Label5: TLabel
Left = 12
Top = 156
Width = 72
Height = 12
Caption = '寄件人名址:'
end
object Label10: TLabel
Left = 134
Top = 53
Width = 12
Height = 12
Caption = '年'
end
object Label11: TLabel
Left = 178
Top = 53
Width = 12
Height = 12
Caption = '月'
end
object Label12: TLabel
Left = 222
Top = 53
Width = 12
Height = 12
Caption = '日'
end
object EditOfficeFrom: TEdit
Left = 94
Top = 16
Width = 157
Height = 20
TabOrder = 0
Text = '温州'
OnKeyPress = EditTabKeyPress
end
object EditTelFrom: TEdit
Left = 94
Top = 85
Width = 121
Height = 20
TabOrder = 4
OnKeyPress = EditTabKeyPress
end
object EditZipFrom: TEdit
Left = 94
Top = 119
Width = 77
Height = 20
MaxLength = 6
TabOrder = 5
OnKeyPress = EditTabKeyPress
end
object MemoAddressFrom: TMemo
Left = 94
Top = 153
Width = 246
Height = 45
Alignment = taCenter
Lines.Strings = (
'欧海区人民法院')
TabOrder = 6
end
object EditYear: TEdit
Left = 95
Top = 50
Width = 32
Height = 20
MaxLength = 4
TabOrder = 1
OnKeyPress = EditTabKeyPress
end
object EditMonth: TEdit
Left = 151
Top = 50
Width = 20
Height = 20
MaxLength = 2
TabOrder = 2
OnKeyPress = EditTabKeyPress
end
object EditDay: TEdit
Left = 195
Top = 50
Width = 20
Height = 20
MaxLength = 2
TabOrder = 3
OnKeyPress = EditTabKeyPress
end
end
object ButtonClear: TButton
Left = 476
Top = 190
Width = 75
Height = 25
Caption = '清除'
TabOrder = 6
OnClick = ButtonClearClick
end
end
Unit:
unit UnitMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Mask, Printers;
type
TFormMain = class(TForm)
ButtonPrint: TButton;
ButtonExit: TButton;
GroupBox2: TGroupBox;
ButtonAbout: TButton;
Label6: TLabel;
EditTelTo: TEdit;
Label7: TLabel;
EditZipTo: TEdit;
MemoAddressTo: TMemo;
Label8: TLabel;
Label9: TLabel;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
Label13: TLabel;
EditName1: TEdit;
Label14: TLabel;
EditName2: TEdit;
GroupBox3: TGroupBox;
Label15: TLabel;
Label20: TLabel;
EditWeight: TEdit;
EditMoney: TEdit;
Label16: TLabel;
EditMoneyAll: TEdit;
Label17: TLabel;
EditMoneyOther: TEdit;
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
EditOfficeFrom: TEdit;
EditTelFrom: TEdit;
EditZipFrom: TEdit;
MemoAddressFrom: TMemo;
EditYear: TEdit;
EditMonth: TEdit;
EditDay: TEdit;
ButtonClear: TButton;
MemoDescript: TMemo;
procedure ButtonExitClick(Sender: TObject);
procedure ButtonPrintClick(Sender: TObject);
procedure Image1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure ButtonClearClick(Sender: TObject);
procedure EditTabKeyPress(Sender: TObject;
var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;

const
PRINT_PIX=9;
var
FormMain: TFormMain;
var
PointX,PointY:integer;
implementation
{$R *.DFM}
function PrinterPos(iMM:double;XorY:integer):integer;
begin
if XorY=0 then
Result:=Round(iMM/25.4*PointX);
//X
if XorY=1 then
Result:=Round(iMM/25.4*PointY);
//Y
end;

procedure TFormMain.ButtonExitClick(Sender: TObject);
begin
Close;
end;

procedure TFormMain.ButtonPrintClick(Sender: TObject);
var
bmp:Tbitmap;
begin
PointX:=GetDeviceCaps(Printer.Handle,LOGPIXELSX);
PointY:=GetDeviceCaps(Printer.Handle,LOGPIXELSY);
bmp:=TBitmap.Create;
//bmp.LoadFromFile('test.bmp');
with Printerdo
begin
begin
Doc;
//Canvas.StretchDraw(Rect(0,0,PrinterPos(160,0),PrinterPos(92,1)),bmp);
Canvas.Font.Name:='黑体';
Canvas.Font.Size:=14;
Canvas.TextOut(PrinterPos(10-18,0),PrinterPos(21,1),EditOfficeFrom.Text);
Canvas.Font.Size:=11;
Canvas.TextOut(PrinterPos(35-18,0),PrinterPos(22,1),EditYear.Text);
Canvas.TextOut(PrinterPos(48-18,0),PrinterPos(22,1),EditMonth.Text);
Canvas.TextOut(PrinterPos(57-18,0),PrinterPos(22,1),EditDay.Text);
Canvas.TextOut(PrinterPos(18-18,0),PrinterPos(52,1),EditTelFrom.Text);
Canvas.TextOut(PrinterPos(54-18,0),PrinterPos(52,1),EditZipFrom.Text);
Canvas.TextOut(PrinterPos(90-18,0),PrinterPos(52,1),EditTelTo.Text);
Canvas.TextOut(PrinterPos(124-18,0),PrinterPos(52,1),EditZipTo.Text);

Canvas.TextOut(PrinterPos(84-18+7*6,0),PrinterPos(60+12-4*6,1),EditWeight.Text);
Canvas.TextOut(PrinterPos(102-18+7*6,0),PrinterPos(60+12-4*6,1),EditMoney.Text);
Canvas.TextOut(PrinterPos(84-18+7*6,0),PrinterPos(68+12-4*6,1),EditMoneyOther.Text);
Canvas.TextOut(PrinterPos(102-18+7*6,0),PrinterPos(68+12-4*6,1),EditMoneyAll.Text);

Canvas.TextOut(PrinterPos(18-18,0),PrinterPos(70+12,1),MemoDescript.Lines[0]);
if MemoDescript.Lines.Count>1 then
Canvas.TextOut(PrinterPos(18-18,0),PrinterPos(80+12,1),MemoDescript.Lines[1]);
if CheckBox1.Checked then
Canvas.TextOut(PrinterPos(8-18,0),PrinterPos(65+12,1),'√');
if CheckBox2.Checked then
Canvas.TextOut(PrinterPos(8-18,0),PrinterPos(70+12,1),'√');
if CheckBox3.Checked then
Canvas.TextOut(PrinterPos(8-18,0),PrinterPos(75+12,1),'√');
Canvas.TextOut(PrinterPos(58-18,0),PrinterPos(65+12,1),EditName1.Text);
Canvas.TextOut(PrinterPos(58-18,0),PrinterPos(75+12,1),EditName2.Text);

Canvas.Font.Name:='宋体';
Canvas.Font.Size:=16;
Canvas.TextOut(PrinterPos(10,0),PrinterPos(35,1),MemoAddressFrom.Lines[0]);
if MemoAddressFrom.Lines.Count>1 then
Canvas.TextOut(PrinterPos(10,0),PrinterPos(45,1),MemoAddressFrom.Lines[1]);
Canvas.TextOut(PrinterPos(80+18,0),PrinterPos(35,1),MemoAddressTo.Lines[0]);
if MemoAddressFrom.Lines.Count>1 then
Canvas.TextOut(PrinterPos(80+18,0),PrinterPos(45,1),MemoAddressTo.Lines[1]);
EndDoc;
end;
end;

procedure TFormMain.Image1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
ShowMessage(IntToStr(X));
ShowMessage(IntToStr(Y));
end;

procedure TFormMain.FormCreate(Sender: TObject);
var
Year,Month,Day:word;
begin
DecodeDate(Date,Year,Month,Day);
EditYear.Text:=IntToStr(Year);
EditMonth.Text:=IntToStr(Month);
EditDay.Text:=IntToStr(Day);
end;

procedure TFormMain.ButtonClearClick(Sender: TObject);
begin
EditTelFrom.Text:='';
EditZipFrom.Text:='';
EditTelTo.Text:='';
EditZipTo.Text:='';
MemoAddressTo.Lines.Clear;
MemoDescript.Lines.Clear;
EditName1.Text:='';
EditName2.Text:='';
EditWeight.Text:='';
end;

procedure TFormMain.EditTabKeyPress(Sender: TObject;
var Key: Char);
begin
if Key = #13 then
begin
SelectNext(Sender as TWinControl, True, True );
Key := #0;
end;
end;

end.

可惜你只有27分,太少了些。
 
用cell做的套打
procedure Tfrm_newpj.bt_printClick(Sender: TObject);
var
apppath:string;
sql_str:string;
qry:Tquery;
i,j,m:integer;
sfbz:string;
sfje:real;
sfje_str:string;
jiao,fen,tmp:string;
begin
bt_commit.Click;
application.CreateForm(tfrm_qrpzh, frm_qrpzh);
if frm_qrpzh.ShowModal = mrok then
begin
qry:=createqry('db');
qry.Close;
qry.SQL.Clear;
sql_str:='select sftjsk.jksbh,sftjsk.tzrq,sftjsk.jfr_dw,sftjsk.jfr_mc,sftjsk.jkpzhm,sftjsk.sfje as hj,'+
' sftjsmxk.sfje,sftjsmxk.sfxmbh,sftjsmxk.jfsl,'+
' sfxmk.sfxmmc,sfxmk.sfjldw,sfxmk.sfsx,sfxmk.sfxx,'+
' jkfsk.jkfs_name'+
' from sftjsk,sftjsmxk,jkfsk,sfxmk'+
' where sftjsk.zd=sftjsmxk.zd'+
' and sftjsk.id=sftjsmxk.id'+
' and sftjsk.jksbh='''+jksbh.Text+''''+
' and sftjsk.jkfs=jkfsk.jkfs_id'+
' and sfxmk.sfxmbh=sftjsmxk.sfxmbh';



qry.SQL.Add(sql_str);
qry.Open;
apppath:=ExtractFilePath(application.ExeName) + 'pj/';
cel_print.DoLogin('财政部计算中心',157,'0cfd6cffc001920498fe6100f309');
cel_print.DoOpenFile(apppath+'lnpy.cll');
// 对cell单元格赋值
with cel_printdo
begin
do
setcelldata(1,2,' '+formatdatetime('yyyy',dtp.date)+' '+formatdatetime('mm',dtp.date)+' '+formatdatetime('dd',dtp.date));
do
SetCellData(5,2,dm_pas.DM.sfdwxxk.FieldByName('sfdwdm').asstring);
do
SetCellData(5,3,dm_pas.DM.sfdwxxk.FieldByName('sfdwmc').asstring);
do
SetCellData(1,4,qry.FieldByName('jfr_dw').asstring);
do
SetCellData(1,5,qry.FieldByName('jfr_mc').asstring);
do
SetCellData(5,4,qry.FieldByName('jkfs_name').asstring);
do
SetCellData(5,5,qry.FieldByName('jkpzhm').asstring);
do
SetCellData(1,14,dx.Caption);
sfje:=qry.fieldbyname('hj').asfloat;
sfje_str:=formatfloat('0.00',sfje);
fen:=RightN(sfje_str,1);
jiao:=copy(RightN(sfje_str,2),1,1);
do
setcelldata(15,14,fen);
do
setcelldata(14,14,jiao);
m:=0;
for j:=length(sfje_str)-3do
wnto 1do
begin
tmp:=copy(sfje_str,1,j);
do
setcelldata(13-m,14,RightN(tmp,1));
m:=m+1;
end;
do
setcelldata(13-m,14,'¥');
m:=0;
for i:=0 to qry.RecordCount-1do
begin
do
setcelldata(0,8+i,qry.fieldbyname('sfxmbh').asstring);
do
setcelldata(1,8+i,qry.fieldbyname('sfxmmc').asstring);
do
setcelldata(2,8+i,qry.fieldbyname('sfjldw').asstring);
if (qry.fieldbyname('sfxx').asstring <> '') and (qry.fieldbyname('sfsx').asstring <> '') then
sfbz:= qry.fieldbyname('sfxx').asstring + '-' + qry.fieldbyname('sfsx').asstring;
if (qry.fieldbyname('sfxx').asstring <> '') and (qry.fieldbyname('sfsx').asstring = '') then
sfbz := qry.fieldbyname('sfxx').asstring;
if (qry.fieldbyname('sfxx').asstring = '') and (qry.fieldbyname('sfsx').asstring <> '') then
sfbz := qry.fieldbyname('sfsx').asstring;
do
setcelldata(3,8+i,qry.fieldbyname('jfsl').asstring);
sfje:=qry.fieldbyname('sfje').asfloat;
sfje_str:=formatfloat('0.00',sfje);
fen:=RightN(sfje_str,1);
jiao:=copy(RightN(sfje_str,2),1,1);
do
setcelldata(15,8+i,fen);
do
setcelldata(14,8+i,jiao);
for j:=length(sfje_str)-3do
wnto 1do
begin
tmp:=copy(sfje_str,1,j);
do
setcelldata(13-m,8+i,RightN(tmp,1));
m:=m+1;
end;
do
setcelldata(13-m,8+i,'¥');
do
setcelldata(4,8+i,sfbz);
end;

do
SetCellData(2,3,qry.fields[0].asstring);
do
SetCellData(7,1,jksbh.text);
do
setcelldata(12,16,czy_xm);
// 对cell单元格赋值
//begin
print
do
Print (false);
//end print
end;
 
adnil高手谢谢你拉
致意崇高的敬意
 
后退
顶部