long mode 分页_整理一下关于分栏及分页打印.该如何解决

VB codeOption 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值