整理一下关于分栏及分页打印.

king06 2010-06-21 03:46:02
刚刚浏览了帖子,又看到有问这个问题的,所以发一个之前我写的分栏打印的代码供参考,希望对以后出现此类问题有所帮助:
(窗体上两个MSHFlexGrid,左右各一)
Option Explicit
Private RsPrint As ADODB.Recordset
Private CurPos As Long '游标当前记录的位置
Private SumPagesMoney As Currency
Private SumPagesCount As Long

Public Function DoModal(vRst As ADODB.Recordset)'记录源自己写好,传进来
Set RsPrint = vRst
frmPrint.Show
End Function

Private Sub Form_Load()
With frmPrint
.Appearance = 0
.AutoRedraw = 1
.BackColor = &H80000005 '背景颜色:白色
.BorderStyle = 0
.Height = 15000 '设置页面的大小(纸的大小)
.Width = 11760
.Top = 0
.Left = 0
.ClipControls = 0 'False
.FillStyle = 0 'Solid
.Caption = "paper"
End With
Label5.Caption = Trim(custdaily.Text1.Text)
Label10.Caption = Trim(custdaily.Text3.Text)

Call InitMSFG(MSHFlexGrid1)
Call InitMSFG(MSHFlexGrid2)

RsPrint.PageSize = MSHFlexGrid1.Rows - 1 '设置记录集中记录页里记录条数,也即要显示在每栏上的记录条数
CurPos = 0
SumPagesMoney = 0
SumPagesCount = 0
GoPrint '打印...
End Sub

Private Sub GoPrint()
Dim rc As Integer, cc As Integer '一页一栏的行数rc,列数cc
Dim prc As Integer '记录集内记录的总页数
Dim rctotal As Integer '总行数
Dim i As Integer
Me.Height = 15000
' Printer.ScaleMode = vbMillimeters

If RsPrint.RecordCount > 0 Then
prc = RsPrint.PageCount '
rctotal = RsPrint.RecordCount

RsPrint.MoveLast: RsPrint.MoveFirst
For i = 1 To RsPrint.RecordCount
SumPagesMoney = SumPagesMoney + Val(RsPrint.Fields(1).Value)
' SumPagesCount = SumPagesCount + Val(RsPrint.Fields(2).Value)
RsPrint.MoveNext
Next

RsPrint.MoveLast: RsPrint.MoveFirst
For i = 1 To prc Step 2
Call InitMSFG(MSHFlexGrid1)
Call InputMSFG(i, RsPrint, MSHFlexGrid1) '第一栏内容
If i + 1 <= RsPrint.PageCount Then
Call InitMSFG(MSHFlexGrid2)
Call InputMSFG(i + 1, RsPrint, MSHFlexGrid2) '第二栏内容
Else
MSHFlexGrid2.Visible = False
MSHFlexGrid2.Clear
End If

'页脚处理
Call LoacalSum(rctotal, i \ 2 + 1, IIf(prc Mod 2 = 0, prc / 2, prc \ 2 + 1))

' MsgBox ("打印第" & Fix(I / 2) + 1 & "页")
Me.PrintForm '输出到系统缺省打印机
Next
Else
MsgBox "查无此记录"
End If

' RsPrint.Close '关闭记录
' Set RsPrint = Nothing '释放缓冲区
End Sub

Private Sub InitMSFG(vMSF As MSHFlexGrid)
With vMSF
.Clear
.Top = 780

.Rows = 51 '设置一栏容纳的行数(包括列表头)
.Cols = 4
.FixedCols = 0
.FixedRows = 0
.BackColorFixed = 255
.BackColorBkg = -2147483639
.GridColor = 8454016
.GridColorFixed = 8454143
.Gridlines = 1
.MergeCells = 4
.BorderStyle = 1 '设置边框:有边框
.Appearance = 0

.ColWidth(0) = 600
.ColWidth(1) = 2600
.ColWidth(2) = 1500
.ColWidth(3) = 800
.TextMatrix(0, 0) = "序号"
.TextMatrix(0, 1) = "客户名称"
.TextMatrix(0, 2) = "总计金额"
.TextMatrix(0, 3) = "备注"

.Width = 5500 '设置宽度容纳一栏所有的列。
End With
MSHFlexGrid2.Left = MSHFlexGrid1.Left + MSHFlexGrid1.Width + 100
End Sub

'读取记录集中(vMSFG行数)的多条记录
Private Sub InputMSFG(vIntPage As Integer, rstData As ADODB.Recordset, vMSFG As MSHFlexGrid)
Dim i As Long, j As Long
Dim mMoney As Currency, mCount As Long
Dim mRowHeight As Integer
mRowHeight = vMSFG.RowHeight(0)

' rstData.AbsolutePosition = (vIntPage - 1) * rstData.PageSize + 1'仅向前游标或动态游标无用
For i = 1 To vMSFG.Rows - 1
If CurPos < RsPrint.RecordCount Then
CurPos = CurPos + 1
With vMSFG
.Row = i
.TextMatrix(i, 0) = CurPos

.TextMatrix(i, 1) = rstData.Fields(0).Value & ""
.TextMatrix(i, 2) = Format(rstData.Fields(1).Value & "", "0.00")
End With
mMoney = mMoney + Val(rstData.Fields(1).Value)
' mCount = mCount + Val(rstData.Fields(2).Value)
mRowHeight = mRowHeight + vMSFG.RowHeight(i)
rstData.MoveNext
End If
Next

With vMSFG
If .Row < .Rows - 1 Then '若最后一页的记录不够填充整张表
.Rows = .Row + 1
End If

.Rows = .Rows + 1
.TextMatrix(.Rows - 1, 0) = "小计"
.TextMatrix(.Rows - 1, 1) = ""
.TextMatrix(.Rows - 1, 2) = Format(mMoney, "0.00")
.TextMatrix(.Rows - 1, 3) = ""
.Height = mRowHeight + .RowHeight(.Rows - 1) '再设置一下表格显示高度
End With
End Sub

Private Sub LoacalSum(ByVal vIntI As Integer, ByVal vIntJ As Integer, ByVal vIntK As Integer)
'下置一横线,写总计之类
Label8.Caption = "(" & "金额" & ")" & Format(Val(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Rows - 1, 2)) + Val(MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Rows - 1, 2)), "0.00")
Label3.Caption = "(" & "金额" & ")" & Format(SumPagesMoney, "0.00")
Label6.Caption = "共" & vIntI & "条," & vIntJ & "/" & vIntK & "页"

Line1.x1 = MSHFlexGrid1.Left
Line1.X2 = MSHFlexGrid1.Left + MSHFlexGrid1.Width + 100 + MSHFlexGrid2.Width
Line1.y1 = MSHFlexGrid1.Top + MSHFlexGrid1.Height + 300
Line1.Y2 = Line1.y1

Label7.Left = MSHFlexGrid1.Left: Label8.Left = Label7.Left + Label7.Width + 100
Label7.Top = Line1.y1 + 100: Label8.Top = Label7.Top
Label2.Left = Label7.Left: Label3.Left = Label8.Left
Label2.Top = Label7.Top + Label7.Height + 100: Label3.Top = Label2.Top

Label6.Left = Me.ScaleWidth - Label6.Width - 200
Label6.Top = Me.ScaleHeight - Label6.Height - 200

Label10.Left = Me.ScaleWidth - Label10.Width - 600
Label9.Left = Label10.Left - Label9.Width - 50
Label5.Left = Label9.Left - Label5.Width - 50
Label4.Left = Label5.Left - Label4.Width - 50
End Sub




...全文
271 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
做个记号,以后用得着
yangao 2010-06-21
  • 打赏
  • 举报
回复
学习~~~
孤独剑_LPZ 2010-06-21
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 chinaboyzyq 的回复:]
引用 2 楼 a124819202 的回复:


马夹好!
[/Quote]
king06 2010-06-21
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 chinaboyzyq 的回复:]
引用 2 楼 a124819202 的回复:


马夹好!
[/Quote]
天热了,不带马夹,,,,,,,这个小哥经常跟着我,就因为咱长得有点像...
lxq19851204 2010-06-21
  • 打赏
  • 举报
回复
感谢分享
chinaboyzyq 2010-06-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 a124819202 的回复:]

[/Quote]
马夹好!
chinaboyzyq 2010-06-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jhone99 的回复:]

感谢分享
[/Quote]
lyserver 2010-06-21
  • 打赏
  • 举报
回复
支持,顶!
a124819202 2010-06-21
  • 打赏
  • 举报
回复
jhone99 2010-06-21
  • 打赏
  • 举报
回复
感谢分享
本课程演示的是一套基于SpringBoot 电子商城网站,主要针对计算机相关专业的正在做毕设的学生与需要项目实战练习的Java学习者和爱好者。本教程适合有一定 Java基础的童鞋,如可进入我的主页学习Java基础,先学基础、先学基础、先学基础,重要的事说三遍。如果你基础不错或者你只想要这个系统的源码。  系统共分为以下几个模块:首页导航栏轮播图分栏推荐 搜索显示关键词搜到的产品能通过产品进入详情页 详情页显示商品详情多图画廊展示购物车 购物车显示加入购物车产品信息 登录注册实现登录注册功能 后台管理后台首页商品管理用户管理 技术实现 IOC容器:SpringBoot持久层:MyBatis数据源:druid 日志:log4j 前端框架:jstl   首页界面  ------------------------------------------------------------------------------------------------------------------------   1. 详细的功能说明文档 2. 从 0到1 开始部署运行本套系统 3. 该项目附带的源码资料及开发工具可以使用 4. 提供技术答疑和协助指导等 5. 本套教程包含:系统源码、系统项目文档、数据库脚本SQL、开发软件工具等 6. 如果你对系列课程中其他教程有需要,联系告知老师,提前录制 7. 整套系列课程都在陆续更新中 ------------------------------------------- ​更多详细内容在课后文档 ------------------------------------------ 

1,216

社区成员

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

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