ListView ,MSFlexGrid 直接输出到打印机的函数写法!问题解决人:laviewpbt(人一定要靠自己) ,mylzw(芃)

这是一个关于如何将ListView和MSFlexGrid内容打印的VB代码实现。提供了两个函数,一个用于打印MSFlexGrid,另一个用于将ListView数据转换成MSFlexGrid。代码详细展示了如何设置打印边界、计算单元格宽度、格式化数据以及处理打印页眉和页脚。
摘要由CSDN通过智能技术生成

把ListView 里的内容做个参数为ListView 对象,使用VB的Printer 对象打印出来的函数!下面是打印MSFlexGrid 的代码,不知道怎么打印我说的ListView!
以下是参考代码:
Sub print_grid(Grd As MSFlexGrid, MainTitle As String, SecTitle As String, PageLine As Integer, DjCol As Integer, JeCol As Integer)
 Dim x0 As Single, y0 As Single
 Dim x As Single, y As Single
 Dim fs As String * 10
 Dim zje As Currency, yje As Currency
 Dim HzNum As Integer
 Dim n As Integer, r As Integer

 Dim dx(0 To 20) As Integer
 Dim Cellf(0 To 20) As Single

 Dim str1 As String, str2 As String, str3 As String, str4 As String
 Dim I As Integer, j As Integer, k As Integer
 'Load printer
 'printer.Show
 If Grd.Rows <= 1 Then
     MsgBox "本表格没有数据,没有必要打印!", 48, "提示"
     Exit Sub
 End If
 x0 = 10    '打印边界
 y0 = 20
 With Grd
 '计算栏空  dx(i)
 .Row = 1
 w = .Width
 For I = .Cols - 1 To 1 Step -1
        .Col = I
        dx(I) = (.CellWidth + 72) / 56.7 / 4.233
        w = w - (.CellWidth + 72)
 Next I
 dx(0) = w / 4.233 / 56.7
 '计算 str1 到 str4
 str1 = "┌"
 str2 = "├"
 str3 = "│"
 str4 = "└"
 HzNum = 1 '汉字总数
 For I = 0 To .Cols - 1
     Cellf(I) = HzNum * 4.233     '计算每栏起始打印位置
     For j = 1 To dx(I)
         str1 = str1 + "─"
         str2 = str2 + "─"
         str3 = str3 + " "
         str4 = str4 + "─"

     Next j
     HzNum = HzNum + dx(I) + 1
     If I < .Cols - 1 Then
        str1 = str1 + "┬"
        str2 = str2 + "┼"
        str3 = str3 + "│"
        str4 = str4 + "┴"
     Else
        str1 = str1 + "┐"
        str2 = str2 + "┤"
        str3 = str3 + "│"
        str4 = str4 + "┘"
     End If
 Next I

Printer.ScaleMode = 6      '毫米为单位
Printer.Width = 210 * 56.7   '窄行打印纸大小
Printer.Height = 297 * 56.7
k = 1
n = 0    '当前页数
zje = 0  '总计金额

r = Int((.Rows + PageLine - 2) / PageLine)   '总页数
While k <= .Rows - 1
    yje = 0    '页小计金额
'    printer.FontName = "楷书"
    Printer.FontName = "宋体"

    Printer.FontBold = True
    Printer.FontSize = 18
    x = x0 + (HzNum * 4.233 - Len(MainTitle) * 6.46) / 2
    y = y0


    Printer.CurrentX = x
    Printer.CurrentY = y
    Printer.Print MainTitle      '打印主标题

    Printer.FontBold = False
    Printer.FontName = "宋体"
    Printer.FontSize = 12
    y = Printer.CurrentY + 3
    x = x0
    Printer.CurrentX = x
    Printer.CurrentY = y
    Printer.Print SecTitle      '打印次标题
    Printer.CurrentX = x + HzNum * 4.233 - 50
    Printer.CurrentY = y
    Printer.Print Format$(Date, "yyyy-mm-dd")      ''打印日期


    y = Printer.CurrentY + 2
    Printer.CurrentX = x0
    Printer.CurrentY = y
    Printer.Print str1                    '打印┌───┬──┬─┐

    y = Printer.CurrentY
    Printer.CurrentX = x0
    Printer.Print str3                    '打印│      │    │  │
    For j = 0 To .Cols - 1                '打印表头内容
        '表头内容位于单元中间
        Printer.CurrentX

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值