把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