请提供一个简单的打印程序!!!!!!!!!!!!!!!!

boxzang 2003-09-30 10:06:37
就是打印datagrid里的数据!
...全文
63 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
嬉皮 2003-09-30
  • 打赏
  • 举报
回复
使用printer 对象
watt 2003-09-30
  • 打赏
  • 举报
回复
换TrueDBGrid好了,一切问题都解决,包括打印及打印预览。
wx05 2003-09-30
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim beginpage, endpage, numcopies, orientation, i
CommonDialog1.CancelError = True
On Error GoTo errhandler
CommonDialog1.ShowPrinter
beginpage = CommonDialog1.FromPage
endpage = CommonDialog1.ToPage
numcopies = CommonDialog1.Copies
orientation = CommonDialog1.orientation
For i = 1 To numcopies
Next
Exit Sub
errhandler:
Exit Sub
end sub


Micro_Sheng 2003-09-30
  • 打赏
  • 举报
回复

'制定打印位置及分页打印子程序
'需放置一个 MSHFlexGrid 控件 名字设为 Grid1

Sub Print1(ByVal sTableHead As String, ByVal iPrintRows As Integer, ByVal iPrintCols As Integer)
Dim StartX As Integer, StartY As Integer, StartX_Const As Integer, StartY_Const As Integer
Dim RowsOfPage As Integer, CurrentPageNo As Integer, CurrentRowsNo As Integer
Dim RowsNo As Integer, ColsNo As Integer
Dim TableWidth As Integer, RowWidth As Integer, ColWidth As Integer
Dim Font As Integer
Dim PageFoot As String

'
CurrentPageNo = 1
RowsOfPage = 41 '定义每页行数
StartX = 2100 '定义X方向起始位置
StartX_Const = 2100
StartY = 1400 '定义Y方向起始位置
StartY_Const = 1400
RowWidth = 300 '定义行宽
ColWidth = 1440 '定义列宽
TableWidth = ColWidth * iPrintCols '计算表格总宽度
Font = 10 '
Printer.FontName = "宋体" '

prnt1 4860, 700, 15, sTableHead

Printer.Line (StartX - 50, StartY - 30)-(StartX - 50 + TableWidth, StartY - 30)
For RowsNo = 0 To iPrintRows - 1
Grid1.Row = RowsNo
StartX = StartX_Const
CurrentRowsNo = CurrentRowsNo + 1
Printer.Line (StartX_Const - 50, StartY - 30 + RowWidth)-(StartX_Const - 50 + TableWidth, StartY - 30 + RowWidth)
For ColsNo = 0 To iPrintCols - 1
Grid1.Col = ColsNo
prnt1 StartX, StartY + 30, Font, Grid1.Text
StartX = StartX + ColWidth
Next ColsNo

If CurrentRowsNo >= RowsOfPage Then
CurrentRowsNo = 0
'以下打印每页中的页脚
PageFoot = "第" + CStr(CurrentPageNo) + "页"
CurrentPageNo = CurrentPageNo + 1
prnt1 StartX - 1000, StartY + RowWidth + 30, 12, PageFoot
StartX = StartX_Const
'以下打印每页中的竖线
For ColsNo = 0 To iPrintCols
Printer.Line (StartX - 50, StartY_Const - 30)-(StartX - 50, StartY + RowWidth - 30)
StartX = StartX + ColWidth
Next ColsNo

'打印下一页
Printer.NewPage
prnt1 4860, 700, 15, sTableHead
StartX = StartX_Const
StartY = StartY_Const
Printer.Line (StartX - 50, StartY - 30)-(StartX + TableWidth - 50, StartY - 30)

For ColsNo = 0 To iPrintCols - 1
prnt1 StartX - 50, StartY + 30, Font, Grid1.TextMatrix(0, ColsNo)
StartX = StartX + ColWidth
Next ColsNo
StartY = StartY + RowWidth
Printer.Line (StartX_Const - 50, StartY - 30)-(StartX_Const - 50 + TableWidth, StartY - 30)

Else
StartY = StartY + RowWidth
End If
Next RowsNo

'以下在最后一页剩余划空行
If CurrentRowsNo < RowsOfPage Then
For RowsNo = CurrentRowsNo To RowsOfPage
Printer.Line (StartX_Const - 50, StartY - 30)-(StartX_Const - 50 + TableWidth, StartY - 30)
StartY = StartY + RowWidth
Next RowsNo
End If
'以下打印最后一页中的页脚
PageFoot = "第" + CStr(CurrentPageNo) + "页"
prnt1 StartX_Const + iPrintCols * ColWidth - 1000, StartY - 30 - RowWidth + 30, 12, PageFoot
StartX = StartX_Const
'以下打印最后一页中的竖线
For ColsNo = 0 To iPrintCols
Printer.Line (StartX - 50, StartY_Const - 30)-(StartX - 50, StartY - RowWidth - 30)
StartX = StartX + ColWidth
Next ColsNo

Printer.EndDoc '打印结束
End Sub

'打印内容的子程序
Function prnt1(ByVal X As Integer, ByVal Y As Integer, ByVal Font As Single, ByVal txt As String)
Printer.CurrentX = X
Printer.CurrentY = Y
Printer.FontBold = False
Printer.FontSize = Font
Printer.Print txt
End Function

'这是做的一个系统的表格打印程序 楼主试试 你只要作相应修改就应该能符合你的要求!!

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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