我现在用DATE REPORT无法解决的难点:1 每张凭证的行数不同2 打印纸张的大小控制

解决方案 »

  1.   

    直接用Printer对象
    设置Printer的width和height,决定自定义纸张的大小
    设置Printer的CurrentX、CurrentY,在指定的位置输出字符
      

  2.   

    用Printer对象打印,CurrentX、CurrentY为X,Y坐标
    Dim PX, PY As Single'偏移量
    dim sName as String
    Printer.ScaleMode = vbMillimeters '设置打印单位为毫米
    Printer.FontName = "宋体" '打印字体
    Printer.FontSize = 13 '打印字号
    Printer.PaperSize = vbPRPSA4 '打印纸张为A4纸rinter.CurrentX = 26 + PX '打印姓名
    Printer.CurrentY = 45 + (7 - 4.6) / 2 + PY
    Printer.Print sNamePrinter.EndDoc
      

  3.   

    '下面是我一年前做的一个套大的一部分代码 比较烂 你看下吧 
     Dim i, j As Integer
       Dim strdep As String   '部门名称
       Dim strName As String   '人员名称
       Dim strDate As String    '日期
       Dim envHei  As Integer   '信封高度
       Dim preRow As Integer    '当前行
       Const myheight = 1000       '固定高度
       Const mywidth = 1000        '固定宽度
       
       Const mytop1 = 1550         '最顶端高度      1550   1650
       Const mytop2 = 12670        '第二个最顶端高度   12670  12670
       Const mxtop = 1980           '明细高度          1800    1800
       Const mxtop2 = 12970         '第二个明晰高度    12970   12970
       Const sep = 300             '行间距
        Dim depX, depY, depwidth, depheight As Integer      '部门宽度
        Dim nameX, nameY, namewidth, nameheight As Integer      '姓名宽度
        Dim dateX, dateY, datewidth, dateheight As Integer        '日期宽度
        Dim left(5) As Integer       '各列的x
        Dim myPages As Integer       ' 页数
        On Error Resume Next
        
        If Grid1.Rows < 2 Then
            MsgBox "没有任何记录!", vbInformation + vbOKOnly, "提示"
            Exit Sub
        End If
        
        
        strdep = Grid1.TextMatrix(myPages + 1, Grid1.Cols - 1)    '部门名称
        strName = Grid1.TextMatrix(myPages + 1, 7)                 '临时人员姓名  需要改动
        strDate = Grid1.TextMatrix(myPages + 1, 6)
        
        envheight = 5225    'tips
        envHei = 6200               '设定信封高度
        preRow = 0                  '当前行为第0行
        depX = 700: depY = 2300: depwidth = 2000: depheight = 1000
        nameX = 700: nameY = 2950: namewidth = 2000: nameheight = 1000
        dateX = 700: dateY = 3600: datewidth = 2000: dateheight = 1000
        For i = 0 To 5
           left(i) = 3500 + 1150 * i
        Next i
         
         frm_print.vp.StartDoc
         With frm_print.vp
             For myPages = Val(txtPage1.Text) To Val(txtPage2.Text) Step 2
             For j = 0 To 1
                    strdep = Grid1.TextMatrix(myPages + j, Grid1.Cols - 1)    '部门名称
                    strName = Grid1.TextMatrix(myPages + j, 7)                 '临时人员姓名  需要改动
                    strDate = Grid1.TextMatrix(myPages + j, 6)
                .FontSize = 16
                .FontBold = True
                .FontName = "隶书"
                .TextBox strdep, depX, depY + j * envheight, depwidth, depheight '部门名称
                .FontSize = 22
                .FontBold = False
                .FontName = "华文行楷"
                .TextBox strName, nameX, nameY + j * envheight, namewidth, nameheight '员工姓名
                .FontSize = 12
                .FontBold = False
                .FontName = "隶书"
                .TextBox strDate, dateX, dateY + j * envheight, datewidth, dateheight '日期
                
                
                
                    .FontSize = 10
                    .FontBold = True
                    .FontName = "黑体"
                    .TextBox "项目", left(0), mytop1 + j * envheight, mywidth, myheight    '项目1列
                    .TextBox "金额", left(1) + 200, mytop1 + j * envheight, mywidth, myheight   '金额1列
        
                     .TextBox "项目", left(2), mytop1 + j * envheight, mywidth, myheight    '项目2列
                     .TextBox "金额", left(3) + 200, mytop1 + j * envheight, mywidth, myheight   '金额2列
        
                     .TextBox "项目", left(4), mytop1 + j * envheight, mywidth, myheight     '项目3列
                     .TextBox "金额", left(5), mytop1 + j * envheight, mywidth, myheight    '金额3列
                
                   '明细(1列)
                   .FontBold = False
                   .FontName = "宋体"
                  For mxcol = 8 To Grid1.Cols - 1
                      If mxcol - 8 > 7 Then
                         premxcol = mxcol
                         Exit For
                      End If
    '                  .TextAlign = taLeftMiddle
                      .TextBox Grid1.TextMatrix(0, mxcol), left(0), mxtop + (mxcol - 8) * sep + j * envheight, mywidth, myheight
    '                   .TextAlign = taRightMiddle
                      .TextBox Grid1.TextMatrix(myPages + j, mxcol), left(1) + 200, mxtop + (mxcol - 8) * sep + j * envheight, mywidth, myheight
                  Next mxcol              '明细(2列)
                  For mxcol = premxcol To Grid1.Cols - 2
                      If mxcol - 8 > 15 Then
                          premxcol = mxcol
                          Exit For
                      End If
    '                  .TextAlign = taLeftMiddle
                      .TextBox Grid1.TextMatrix(0, mxcol), left(2), mxtop + (mxcol - 16) * sep + j * envheight, mywidth, myheight
    '                  .TextAlign = taRightMiddle
                      .TextBox Grid1.TextMatrix(myPages + j, mxcol), left(3) + 200, mxtop + (mxcol - 16) * sep + j * envheight, mywidth, myheight
                  Next mxcol
                  '明细(3列)              For mxcol = premxcol To Grid1.Cols - 2
                      If mxcol - 8 > 23 Then
                         premxcol = mxcol
                         Exit For
                      End If
    '                  .TextAlign = taLeftMiddle
                      .TextBox Grid1.TextMatrix(0, mxcol), left(4), mxtop + (mxcol - 24) * sep + j * envheight, mywidth, myheight
    '                  .TextAlign = taRightMiddle
                      .TextBox Grid1.TextMatrix(myPages + j, mxcol), left(5), mxtop + (mxcol - 24) * sep + j * envheight, mywidth, myheight
                  Next mxcol
     
                  .DefaultDevice = True
                  .PageHeight = 850
                  If myPages >= frm_main.Grid1.Rows - 1 Then
                      frm_print.vp.EndDoc
                      frm_print.Show 1
                      Exit Sub
                  End If
                  
                  Next j
                 .NewPage
              Next myPages
         End With
        frm_print.vp.EndDoc
        frm_print.Show 1