票据打印的问题

flashrain 2003-11-25 10:07:20
想做一个财务中票据打印的小东西,需要那些控件,特别是打印位置该怎么控制?有没有这方面的代码
...全文
59 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
LCAAA 2003-12-02
  • 打赏
  • 举报
回复
也可以用水晶报表,先把票据的样式做好后,通过程序语句给报表中的字段负值就可以了。然后在调节每个字段的位置和纸张的大小就可以了。
flashrain 2003-12-01
  • 打赏
  • 举报
回复
up
flashrain 2003-11-28
  • 打赏
  • 举报
回复
up
pbabi 2003-11-27
  • 打赏
  • 举报
回复
倒底是printer对象打印好控制,还是水晶报表或者activereport好控制呢?
flashrain 2003-11-27
  • 打赏
  • 举报
回复
up
饮水需思源 2003-11-26
  • 打赏
  • 举报
回复
用printer对象写打印代码
海牛 2003-11-26
  • 打赏
  • 举报
回复
强烈建议!!!!!!!!!!!!!!!!!!!!1使用Printer对象~!~
online 2003-11-26
  • 打赏
  • 举报
回复
一些资料
用printer对象打印表格

用msflexgrid控件显示的表格,要将它打印出来,最简单的方法是用printform方法,然而这只适合于数据正好能被屏幕显示的,即数据量少的,而且这种打印效果很差。而用printer对象进行打印编程,虽然麻烦点,但效果却是相当不错的,你可以自定义打印格式,打印页数,表格的粗细,字体大小等。实际上用printer对象进行打印编程是比较简单的。

下面我就用一实例来说明:

打印的内容是一张数据表,这里就只有两列数据,包括标题,副标题。(用A4纸打印)

假设数据处在C_DataArray(),和R_DataArray()中C_Name与R_Name分别为两数据项的字段名

Public Sub Printtable()
'初始化

Dim printer1 as Printer

Dim pageheader
Dim pagefooter
Dim pageleft
Dim pageright
Dim usewidth
Dim useheight
Dim i, j, k As Integer
Dim word As String
Dim startx
Dim starty
Dim startyline ‘ 用来纪录打印竖线的起点

Dim endyline ’ 用来纪录打印竖线的末点

设置页面参数

pageheader = 25
pagefooter = 25
pageleft = 20
pageright = 20


With printer1
.PaperSize = 9
.ScaleMode = 6
.FontBold = True
.ScaleLeft = -20
.ScaleTop = -25
.ScaleWidth = 210 '设置为A4纸
.ScaleHeight = 297
usewidth = .ScaleWidth - 40
useheight = .ScaleHeight - 50
.CurrentX = 0
.CurrentY = 0
.DrawWidth = 5
End With
'打印标题
With printer1
.FontSize = 20
.CurrentX = (usewidth - .TextWidth(DataTitle)) / 2
.CurrentY = pageheader + .ScaleTop
End With
printer1.Print DataTitle

'打印副标题
printer1.FontSize = 15
word = DataTitle2
printer1.CurrentX = usewidth - printer1.TextWidth(word)
printer1.Print word

'打印第一条线 Line方法不能用在with ....end with里

printer1.CurrentX = pageleft + printer1.ScaleLeft
startyline = printer1.CurrentY
'线宽

printer1.Line -((printer1.ScaleLeft + printer1.ScaleWidth - pageleft), printer1.CurrentY)
printer1.FontSize = 10
'printer1.Print vbLf
printer1.CurrentY = printer1.CurrentY + 1
'打印第一个字段名
starty = printer1.CurrentY
printer1.CurrentX = ((printer1.ScaleWidth - 40) / 2 - printer1.TextWidth(C_Name)) / 2

printer1.Print C_Name


'打印第二个字段名
printer1.CurrentX = usewidth / 2 + ((usewidth / 2 - printer1.TextWidth(R_Name)) / 2)
printer1.CurrentY = starty
printer1.Print R_Name
printer1.CurrentY = printer1.CurrentY + 1


'打印数据和横线,rownum为数据行数

For i = 1 To rownum
'判断是否该页已打满
If printer1.CurrentY >= useheight Then

'打印横线
printer1.CurrentX = printer1.ScaleLeft + pageleft
printer1.Line -((printer1.ScaleLeft + printer1.ScaleWidth - pageleft), printer1.CurrentY)
printer1.CurrentY = printer1.CurrentY + 1


'打印三条竖线
endyline = printer1.CurrentY
printer1.Line (0, startyline)-(0, endyline)
printer1.Line (usewidth / 2, startyline)-(usewidth / 2, endyline)
printer1.Line (usewidth, startyline)-(usewidth, endyline)

'打印页号
With printer1
.CurrentX = (.ScaleWidth - .TextWidth(.Page)) / 2 - pageleft
.CurrentY = useheight + 3
End With
printer1.Print printer1.Page
printer1.NewPage
With printer1
.CurrentX = pageleft + .ScaleLeft
.CurrentY = pageheader + .ScaleTop
startyline = .CurrentY
End With

End If

'打印一行数据
printer1.CurrentX = ((printer1.ScaleWidth - 40) / 2 - printer1.TextWidth(C_DataArray(i))) / 2
starty = printer1.CurrentY
printer1.Print C_DataArray(i)
printer1.CurrentX = (printer1.ScaleWidth - 40) / 2 + ((printer1.ScaleWidth - 40) / 2 - printer1.TextWidth(R_DataArray(i) )) / 2
printer1.CurrentY = starty
printer1.Print R_DataArray(i)
printer1.CurrentY = printer1.CurrentY + 1
Next i
'打印最后一条横线
printer1.CurrentX = printer1.ScaleLeft + pageleft
printer1.Line -((printer1.ScaleLeft + printer1.ScaleWidth - pageleft), printer1.CurrentY)
endyline = printer1.CurrentY
'打印三条竖线
printer1.Line (0, startyline)-(0, endyline)
printer1.Line (usewidth / 2, startyline)-(usewidth / 2, endyline)
printer1.Line (usewidth, startyline)-(usewidth, endyline)


'打印页号
With printer1
.CurrentX = (.ScaleWidth - .TextWidth(.Page)) / 2 - pageleft
.CurrentY = useheight + 3
End With
printer1.Print printer1.Page

printer1.EndDoc
end sub
fleshboy 2003-11-26
  • 打赏
  • 举报
回复
制定一个票据布局的ini文件
然后用Printer打
Printer.CurrentX
Printer.CurrentY
planetike 2003-11-26
  • 打赏
  • 举报
回复
直接用printer进行套打就行了。
online 2003-11-26
  • 打赏
  • 举报
回复
一个例子
Private Sub Command1_Click()
' Use 1 inch margins.
Const TOP_MARGIN = 1440
Const LEFT_MARGIN = 1440

Dim bottom_margin As Single
Dim db As Database
Dim qdef As QueryDef
Dim rs As Recordset
Dim dbname As String
Dim the_year As Integer
Dim the_value As Integer

MousePointer = vbHourglass
DoEvents

' Open the database.
dbname = App.Path
If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
dbname = dbname & "data.mdb"
Set db = OpenDatabase(dbname)

' Get the records.
Set qdef = db.CreateQueryDef("", _
"SELECT Year, Value FROM YearlyValues")
Set rs = qdef.OpenRecordset(dbOpenSnapshot)

' Read the data and print it.
bottom_margin = Printer.ScaleTop + _
Printer.ScaleHeight - 1440
rs.MoveFirst

Printer.CurrentY = TOP_MARGIN
Do While Not rs.EOF
' Use rs!FieldName to get the data for
' the field named FieldName.
Printer.CurrentX = LEFT_MARGIN
Printer.Print _
Format$(rs!Year, "yyyy") & _
vbTab & _
Format$(rs!Value, "0.0000")

' See if we have filled the page.
If Printer.CurrentY >= bottom_margin Then
' Start a new page.
Printer.NewPage
Printer.CurrentY = TOP_MARGIN
End If

rs.MoveNext
Loop

rs.Close
db.Close

' Finish printing.
Printer.EndDoc

MousePointer = vbDefault
End Sub
射天狼 2003-11-26
  • 打赏
  • 举报
回复
票据打印用PRINTER打印对象控制最容易了!!

Printer.CurrentX = 10
Printer.CurrentY = 20
Printer.Print "打印的内容"
Printer.EndDoc '将结果送到打印机
flashrain 2003-11-26
  • 打赏
  • 举报
回复
网上有套打这方面的资料吗?小弟没学过
bruce tao88 2003-11-26
  • 打赏
  • 举报
回复
用printer套打很好的,特别是打发票一般都用这个。
flashrain 2003-11-26
  • 打赏
  • 举报
回复
小弟初学还没用过printer,那里有这方面资料,能具体点吗?
rainstormmaster 2003-11-25
  • 打赏
  • 举报
回复
使用GDI函数绘图
online 2003-11-25
  • 打赏
  • 举报
回复
建议使用printer对象打印

比较好控制

7,766

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧