急,listview的打印问题,高手帮我看看代码错误,谢谢
急,listview的打印问题,高手帮我看看代码错误,谢谢
楼主fangzhou(_学习狂)2004-03-25 13:55:10 在 VB / 控件 提问 下面的打印代码报错:类型错误,请帮忙,谢谢,完整代码如下:
modMain模块代码:
Option Explicit
Public ChangeX As Boolean
Public mvarNew_TiTle As String "局部复制
Public mvarNew_PageSize As Integer "局部复制
Public mvarNew_PageWidth As Long "局部复制
Public mvarNew_PageHeight As Long "局部复制
Public mvarNew_RowHeight As Integer "局部复制
Public mvarNew_Border As Integer "局部复制
Public mvarNew_PageLeft As Integer "局部复制
Public mvarNew_PageTop As Integer "局部复制
Public mvarNew_Cols As String "局部复制
Public mvarNew_Head10 As String
Public mvarNew_Head11 As String
Public mvarNew_Head2 As String
Public Type PageSetting
sngPageLeft As Single
sngPageTop As Single
sngPageWidth As Single
sngPageHeight As Single
End Type
listViewPrint类代码:
Dim PageLeft As Single
Dim PageTop As Single
Private Type PrintText
caption As String
X As Single
Y As Single
strfont As String
strsize As Integer
bStrickThought As Boolean
End Type
Private Type Cell
x1 As Single
y1 As Single
x2 As Single
y2 As Single
LineWidth As Integer
str As PrintText
End Type
"要引发该事件,请遵循下列语法使用 RaiseEvent:
"RaiseEvent PrintGrid
Public Event PrintPage()
Public Event ShowConfig()
"保持属性值的局部变量
"保持属性值的局部变量
"保持属性值的局部变量
Private mvarN_Head10 As String "局部复制
Private mvarN_Head11 As String "局部复制
Private mvarN_Head2 As String "局部复制
"保持属性值的局部变量
Private mvarGrid As Object "局部复制
Public Property Set N_Grid(ByVal vData As Object)
"向属性指派对象时使用,位于 Set 语句的左边。
"Syntax: Set x.Grid = Form1
Set mvarGrid = vData
End Property
Public Property Get N_Grid() As Object
"检索属性值时使用,位于赋值语句的右边。
"Syntax: Debug.Print X.Grid
Set N_Grid = mvarGrid
End Property
Public Property Let N_Head2(ByVal vData As String)
"向属性指派值时使用,位于赋值语句的左边。
"Syntax: X.N_Head2 = 5
mvarN_Head2 = vData
End Property
Public Property Get N_Head2() As String
"检索属性值时使用,位于赋值语句的右边。
"Syntax: Debug.Print X.N_Head2
N_Head2 = mvarN_Head2
End Property
Public Property Let N_Head11(ByVal vData As String)
"向属性指派值时使用,位于赋值语句的左边。
"Syntax: X.N_Head11 = 5
mvarN_Head11 = vData
End Property
Public Property Get N_Head11() As String
"检索属性值时使用,位于赋值语句的右边。
"Syntax: Debug.Print X.N_Head11
N_Head11 = mvarN_Head11
End Property
Public Property Let N_Head10(ByVal vData As String)
"向属性指派值时使用,位于赋值语句的左边。
"Syntax: X.N_Head10 = 5
mvarN_Head10 = vData
End Property
Public Property Get N_Head10() As String
"检索属性值时使用,位于赋值语句的右边。
"Syntax: Debug.Print X.N_Head10
N_Head10 = mvarN_Head10
End Property
Public Property Let SetChange(ByVal vData As Boolean)
"向属性指派值时使用,位于赋值语句的左边。
"Syntax: X.SetChange = 5
ChangeX = vData
End Property
Public Property Get SetChange() As Boolean
"检索属性值时使用,位于赋值语句的右边。
"Syntax: Debug.Print X.SetChange
SetChange = ChangeX
End Property
Public Sub ShowConfig()
End Sub
Public Property Let N_Cols(ByVal vData As String)
"向属性指派值时使用,位于赋值语句的左边。
"Syntax: X.New_Cols = 5
mvarNew_Cols = vData
End Property
Public Property Get N_Cols() As String
"检索属性值时使用,位于赋值语句的右边。
"Syntax: Debug.Print X.New_Cols
N_Cols = mvarNew_Cols
End Property
Public Property Let N_PageTop(ByVal vData As Integer)
"向属性指派值时使用,位于赋值语句的左边。
"Syntax: X.New_PageTop = 5
mvarNew_PageTop = vData
End Property
Public Property Get N_PageTop() As Integer
"检索属性值时使用,位于赋值语句的右边。
"Syntax: Debug.Print X.New_PageTop
N_PageTop = mvarNew_PageTop
End Property
Public Property Let N_PageLeft(ByVal vData As Integer)
"向属性指派值时使用,位于赋值语句的左边。
"Syntax: X.New_PageLeft = 5
mvarNew_PageLeft = vData
End Property
Public Property Get N_PageLeft() As Integer
"检索属性值时使用,位于赋值语句的右边。
"Syntax: Debug.Print X.New_PageLeft
N_PageLeft = mvarNew_PageLeft
End Property
Public Property Let N_Border(ByVal vData As Integer)
"向属性指派值时使用,位于赋值语句的左边。
"Syntax: X.New_Border = 5
mvarNew_Border = vData
End Property
Public Property Get N_Border() As Integer
"检索属性值时使用,位于赋值语句的右边。
"Syntax: Debug.Print X.New_Border
N_Border = mvarNew_Border
End Property
Public Property Let N_RowHeight(ByVal vData As Integer)
"向属性指派值时使用,位于赋值语句的左边。
"Syntax: X.New_RowHeight = 5
mvarNew_RowHeight = vData
End Property
Public Property Get N_RowHeight() As Integer
"检索属性值时使用,位于赋值语句的右边。
"Syntax: Debug.Print X.New_RowHeight
N_RowHeight = mvarNew_RowHeight
End Property
Public Property Let N_PageHeight(ByVal vData As Long)
"向属性指派值时使用,位于赋值语句的左边。
"Syntax: X.New_PageHeight = 5
mvarNew_PageHeight = vData
End Property
Public Property Get N_PageHeight() As Long
"检索属性值时使用,位于赋值语句的右边。
"Syntax: Debug.Print X.New_PageHeight
N_PageHeight = mvarNew_PageHeight
End Property
Public Property Let N_PageWidth(ByVal vData As Long)
"向属性指派值时使用,位于赋值语句的左边。
"Syntax: X.New_PageWidth = 5
mvarNew_PageWidth = vData
End Property
Public Property Get N_PageWidth() As Long
"检索属性值时使用,位于赋值语句的右边。
"Syntax: Debug.Print X.New_PageWidth
N_PageWidth = mvarNew_PageWidth
End Property
问题点数:100、回复次数:11Top
1 楼fangzhou(_学习狂)回复于 2004-03-25 13:56:51 得分 0
Public Property Let N_PageSize(ByVal vData As Integer)
"向属性指派值时使用,位于赋值语句的左边。
"Syntax: X.New_PageSize = 5
mvarNew_PageSize = vData
End Property
Public Property Get N_PageSize() As Integer
"检索属性值时使用,位于赋值语句的右边。
"Syntax: Debug.Print X.New_PageSize
N_PageSize = mvarNew_PageSize
End Property
Public Property Let N_TiTle(ByVal vData As String)
"向属性指派值时使用,位于赋值语句的左边。
"Syntax: X.New_TiTle = 5
mvarNew_TiTle = vData
End Property
Public Property Get N_TiTle() As String
"检索属性值时使用,位于赋值语句的右边。
"Syntax: Debug.Print X.New_TiTle
N_TiTle = mvarNew_TiTle
End Property
Public Sub PrintPage()
On Error GoTo Print_Err
Dim MyPage As PageSetting
MyPage.sngPageHeight = mvarNew_PageHeight - mvarNew_PageTop
MyPage.sngPageLeft = mvarNew_PageLeft
MyPage.sngPageTop = mvarNew_PageTop
MyPage.sngPageWidth = mvarNew_PageWidth - mvarNew_PageLeft - 18
Dim strHead1 As String
Dim strHead2 As String
Dim strHead3 As String
Dim Grid As ListView
Dim GridCols As String
Dim RowsHeight As Single
Dim LineWidth As Integer
Dim strTitle As String
strTitle = N_TiTle
strHead1 = N_Head10
strHead2 = N_Head11
strHead3 = N_Head2
Set Grid = N_Grid
GridCols = N_Cols
RowsHeight = N_RowHeight
Const HeadHeight = 6
Printer.ScaleMode = 6
PageLeft = MyPage.sngPageLeft
PageTop = MyPage.sngPageTop
Dim AllPages As Long "总页数
Dim RowsPerPage As Long "每页表格行的数量
Dim PerPages As Long "每页的循环变量
Const GridLeft = 0
Const GridTop = 15 + HeadHeight * 2
RowsPerPage = Int((MyPage.sngPageHeight - GridTop - RowsHeight - 35) / RowsHeight) "计算每页的表格行数不包括列头
"给出行数
Dim sGridRow As Long
sGridRow = Grid.ListItems.Count
AllPages = Int((sGridRow + 0.1) / RowsPerPage) + 1
"--计算列宽
Dim lngScaleWidth As Long "表格总宽 计算比例时用
Dim Mycols() As String "存储要打印的列的一维数组
Mycols = Split(GridCols, ",")
Dim MyColX(20) As Single "每一列左右坐标,第0列是mycolx(0)-mycolx(1)
MyColX(0) = 0
For i = 0 To UBound(Mycols) "获取每个需要打印的列宽
lngScaleWidth = lngScaleWidth + Grid.ColumnHeaders.Item(CInt(Mycols(i))).Width
MyColX(i + 1) = lngScaleWidth
Next i
LineWidth = N_Border
For PerPages = 1 To AllPages "每页循环
"--计算标题的左边
Dim titleLonger As Long "-标题共长多少字节
Dim titleLeft As Single
titleLonger = LenB(strTitle)
titleLeft = (MyPage.sngPageWidth - titleLonger * 4) / 2
"--打印标题
printCellOut 0, 0, 0, 0, 0, titleLeft, 0, strTitle, "宋体", 16, False
"--打印头1
printCellOut 0, 0, 0, 0, 0, 0, 15, strHead1, "", 9, False
"--打印头2
printCellOut 0, 0, 0, 0, 0, 0, 15 + HeadHeight, strHead3, "", 9, False
"--计算右对齐的左边
Dim HeadLeft3 As Single
HeadLeft3 = MyPage.sngPageWidth - (LenB(strHead2) * 2)
"--打印头3
printCellOut 0, 0, 0, 0, 0, HeadLeft3, 15 + HeadHeight, strHead2, "", 9, False
"--打印表格(0,28)
Dim NowCol, NowRow As Long
"-打印列头+++++++++++++++++++++++++++++++++++++ 列 头 ++++++++++++++++++++++++++++++++++++++
NowRow = 0
For NowCol = 0 To UBound(Mycols) "一共有几列
printCellOut GridLeft + ((MyColX(NowCol) / lngScaleWidth) * MyPage.sngPageWidth), GridTop + RowsHeight * NowRow, _
GridLeft + ((MyColX(NowCol + 1) / lngScaleWidth) * MyPage.sngPageWidth), GridTop + RowsHeight * (NowRow + 1), _
LineWidth, GridLeft + ((MyColX(NowCol) / lngScaleWidth) * MyPage.sngPageWidth) + 1, GridTop + RowsHeight * NowRow + 1, _
Grid.ColumnHeaders.Item(CInt(Mycols(NowCol))), "宋体", 9, False
Next NowCol
"-打印列头+++++++++++++++++++++++++++++++++++++ 列 头 ++++++++++++++++++++++++++++++++++++++
"-打印表格主体
For NowRow = 1 To RowsPerPage
If Not (NowRow + (PerPages - 1) * RowsPerPage) > sGridRow Then
For NowCol = 0 To UBound(Mycols) "所有列
If Mycols(NowCol) = "1" Then
printCellOut GridLeft + ((MyColX(NowCol) / lngScaleWidth) * MyPage.sngPageWidth), GridTop + RowsHeight * NowRow, _
GridLeft + ((MyColX(NowCol + 1) / lngScaleWidth) * MyPage.sngPageWidth), GridTop + RowsHeight * (NowRow + 1), _
LineWidth, GridLeft + ((MyColX(NowCol) / lngScaleWidth) * MyPage.sngPageWidth) + 1, GridTop + RowsHeight * NowRow + 1, _
Grid.ListItems.Item(NowRow + (PerPages - 1) * RowsPerPage).Text, "宋体", 9, False
Else
printCellOut GridLeft + ((MyColX(NowCol) / lngScaleWidth) * MyPage.sngPageWidth), GridTop + RowsHeight * NowRow, _
GridLeft + ((MyColX(NowCol + 1) / lngScaleWidth) * MyPage.sngPageWidth), GridTop + RowsHeight * (NowRow + 1), _
LineWidth, GridLeft + ((MyColX(NowCol) / lngScaleWidth) * MyPage.sngPageWidth) + 1, GridTop + RowsHeight * NowRow + 1, _
Grid.ListItems.Item(NowRow + (PerPages - 1) * RowsPerPage).SubItems(CInt(Mycols(NowCol)) - 1), "宋体", 9, False
End If
Next NowCol
End If
Next NowRow
"打印页码
printCellOut 0, 0, 0, 0, 0, (MyPage.sngPageWidth - 12) / 2, GridTop + RowsHeight * (NowRow + 1) + 2, "第" + CStr(PerPages) + "页", "", 9, False
Printer.EndDoc
Next PerPages
MsgBox "打印完成! ", vbInformation
Exit Sub
Print_Err:
"清除打印事件
Printer.KillDoc
MsgBox "对不起,打印发生错误,请与供应商联系。 " & vbCrLf _
& Err.Description, vbExclamation
Exit Sub
End Sub
Top
2 楼fangzhou(_学习狂)回复于 2004-03-25 13:57:47 得分 0
Private Sub PrintCell(prnCell As Cell)
"On Error GoTo err1
Printer.ScaleMode = 6
If Not prnCell.LineWidth = 0 Then
Printer.DrawWidth = prnCell.LineWidth
End If
If Not Printer.FillColor = 0 Then
Printer.Line (prnCell.x1, prnCell.y1)-(prnCell.x2, prnCell.y2), , BF
Else
Printer.FillStyle = 1
Printer.Line (prnCell.x1, prnCell.y1)-(prnCell.x2, prnCell.y2), , B
End If
If prnCell.str.strfont = "" Then
prnCell.str.strfont = "宋体"
End If
Printer.Font = prnCell.str.strfont
If prnCell.str.strsize = 0 Then
prnCell.str.strsize = 12
End If
Printer.FontSize = prnCell.str.strsize
Printer.FontStrikethru = prnCell.str.bStrickThought
Printer.CurrentX = prnCell.str.X
Printer.CurrentY = prnCell.str.Y
Printer.Print prnCell.str.caption
Exit Sub
"err1:
" MsgBox Err.Description
End Sub
Private Sub printCellOut(x1 As Single, y1 As Single, x2 As Single, y2 As Single _
, LineWidth As Integer, _
strx As Single, stry As Single, _
strcaption As String, strfont As String, _
strsize As Integer, bThought As Boolean)
Dim printWords As Cell
printWords.x1 = x1 + PageLeft
printWords.y1 = y1 + PageTop
printWords.x2 = x2 + PageLeft
printWords.y2 = y2 + PageTop
printWords.LineWidth = LineWidth
printWords.str.X = strx + PageLeft
printWords.str.Y = stry + PageTop
printWords.str.caption = strcaption
printWords.str.strfont = strfont
printWords.str.strsize = strsize
printWords.str.bStrickThought = bThought
If printWords.x2 < 0 Then
printWords.x2 = 0
End If
If printWords.x1 < 0 Then
printWords.x1 = 0
End If
If printWords.y1 < 0 Then
printWords.y1 = 0
End If
If printWords.y2 < 0 Then
printWords.y2 = 0
End If
If printWords.str.X < 0 Then
printWords.str.X = 0
End If
If printWords.str.Y < 0 Then
printWords.str.Y = 0
End If
PrintCell printWords
End SubTop
3 楼fangzhou(_学习狂)回复于 2004-03-25 13:58:46 得分 0
调用时代码如下:
If lstPro.ListItems.Count = 0 Then Exit Sub
"打印列表
If MsgBox("真的要打印【预订单】列表吗?(Y/N) " & vbCrLf _
& "请设置打印机的纸张:A4 纵向 ", vbInformation + vbYesNo) = vbNo Then
Exit Sub
End If
Dim ptGrid As listViewPrint
"建立打印对象
On Error GoTo Err1
Dim strPageLeft As String
Dim strPageTop As String
Dim PageTop As Long
Dim PageLeft As Long
Set ptGrid = New listViewPrint
ptGrid.N_Border = 1
ptGrid.N_Cols = "1,2,3,4,5,6,7,8,9,10"
Set ptGrid.N_Grid = lstPro
ptGrid.N_TiTle = "【预订单】"
ptGrid.N_Head10 = "制表人:" & UserText
ptGrid.N_Head2 = "制表时间:" & Now
ptGrid.N_PageLeft = XLeft
ptGrid.N_PageTop = XTop
ptGrid.N_PageHeight = 290
ptGrid.N_PageWidth = 200
ptGrid.N_RowHeight = 6
ptGrid.PrintPage
Set ptGrid = Nothing
Exit Sub
Err1:
MsgBox "对不起,打印列表错误。 " & vbCrLf & vbCrLf & Err.Description, vbInformation
Exit SubTop
4 楼yijiansong(不知路在何方)回复于 2004-03-25 14:15:19 得分 20
眼花了,只能帮你顶!Top
5 楼hisofty(瘦马)回复于 2004-03-25 14:37:23 得分 15
贴这么多,眼都花了!Top
6 楼fangzhou(_学习狂)回复于 2004-03-25 15:15:40 得分 0
哪位大侠帮帮忙撒,分不够再加Top
7 楼fangzhou(_学习狂)回复于 2004-03-26 10:05:45 得分 0
没人帮我看看吗?帮我顶一下吧,谢谢。Top
8 楼mengfan19(可乐555)回复于 2004-03-26 10:10:41 得分 0
干脆加QQ吧 讨论讨论 发大段代码上来一般人都没有耐心看完的Top
9 楼mengfan19(可乐555)回复于 2004-03-26 10:11:46 得分 50
9115612 请注明是的朋友Top
10 楼wangzqm(冰雨)回复于 2004-03-26 15:06:34 得分 15
看得头都痛了,只好帮你Up一下Top
11 楼fangzhou(_学习狂)回复于 2004-03-26 18:46:34 得分 0
我把控件打了一个包放到网上了,谁有空帮我看看,谢谢。
ieoa.net/Listprint.rar
调用时代码见上面我最后一个代码贴Top
-
相关文章
2秒记住本站域名
玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的readygo.com.cn
