请问打印一个表格该如何打印?

biti_firefox 2004-09-16 11:08:49
我想用VB自带的Report来做,自己在报表里画了好多线,还比较整齐,里边的数据是我自己写进去的,不需要从数据库读取,我可不可以报这个表格打印出来?可以精确定,请问我该如何做?
...全文
401 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wumylove1234 2004-09-18
  • 打赏
  • 举报
回复
那用AR就可以了.AR可以不用数据绑定.
AR:ActiveReport
XFHUANG 2004-09-18
  • 打赏
  • 举报
回复
Sub print_head()
Printer.FontSize = 9
Printer.Font = "新細明體"
Printer.CurrentX = 0
Printer.CurrentY = 500
Printer.Print "貨 源:國 外 □";
Printer.FontSize = 18
Printer.Font.Bold = True
Printer.Font = "新細明體"
Printer.CurrentX = 3400
Printer.CurrentY = 500
Printer.Print "江 陰 傑 麥 爾 樂 器 有 限 公 司";
Printer.FontSize = 14
Printer.Font.Bold = True
Printer.Font = "新細明體"
Printer.CurrentX = 9700
Printer.Print "驗收單號:"; RS2!訂單號碼
Printer.FontSize = 9
Printer.Font = "新細明體"
Printer.CurrentX = 0
Printer.Print "    國 內 □"
Printer.FontSize = 12
Printer.Font.Bold = True
Printer.Font = "新細明體"
Printer.CurrentX = 450
Printer.Print "廠商編號:"; RS2!廠商編號;
Printer.FontSize = 18
Printer.Font.Bold = True
Printer.Font = "新細明體"
Printer.CurrentX = 5000
Printer.Print "驗收訂購單";
Printer.FontSize = 12
Printer.Font.Bold = True
Printer.Font = "新細明體"
Printer.CurrentX = 9700
Printer.Print "訂購日期: "
Printer.FontSize = 12
Printer.Font.Bold = True
Printer.Font = "新細明體"
Printer.CurrentX = 450
Printer.Print "廠商名稱:"; RS2!廠商名稱;
Printer.CurrentX = 9700
Printer.Print "年   月   日"
Printer.FontSize = 9
Printer.Font.Bold = True
Printer.Font = "新細明體"
Printer.Print "┌────┬────┬───────┬───────────────────┬───┬───┬───┬───┬───┬─────┐"
Printer.Print "│交貨期限│請購單號│品 名 編 號│  品   名   規   格    │單 位│訂購量│交貨量│實收量│單 價│ 總 價 │"
Printer.Print "├────┼────┼───────┼───────────────────┼───┼───┼───┼───┼───┼─────┤"
End Sub
Sub print_detail()
Price = RS2!實收量 * RS2!訂購單價
Printer.FontSize = 9
Printer.Font = "新細明體"
Printer.Print "│    │    │       │                   │   │   │   │   │   │     │";
Printer.CurrentX = 120
Printer.Print RS2!交貨日期;
Printer.CurrentX = 1100
Printer.Print RS2!請購單號;
Printer.CurrentX = 2060
Printer.Print RS2!零件編號;
Printer.CurrentX = 3590
Printer.Print RS2!零件名稱;
Printer.CurrentX = 7750
Printer.Print RS2!單位;
Printer.CurrentX = 8250
Printer.Print RS2!訂購量;
Printer.CurrentX = 10500
Printer.Print RS2!訂購單價
Printer.Print "├────┼────┼───────┼───────────────────┼───┼───┼───┼───┼───┼─────┤"
End Sub
Sub PRINT_END()
Printer.FontSize = 9
Printer.Font.Bold = True
Printer.Font = "新細明體"
Printer.Print "│    │    │       │                   │   │   │   │   │   │     │"
Printer.Print "├────┴────┴───────┴───────────────────┴───┴───┴───┴───┴───┴─────┤"
Printer.Print "│        備   ( 請      憑      此      單      領      款 )   注       │"
Printer.Print "├───────────────────────────────────────────────────────────────┤"
Printer.Print "│                                                               │"
Printer.Print "│                                                               │"
Printer.Print "│                                                               │"
Printer.Print "│                                                               │"
Printer.Print "│                                                               │"
Printer.Print "├───────────────────────────────────────────────────────────────┤"
Printer.Print "│ 小 計:         營業稅:         預付:         扣款:        金額:          │"
Printer.Print "├───────┬───────────────────────┬───────┬───────────────────────┤"
Printer.Print "│ 發   票 │                       │ 收   据 │                       │"
Printer.Print "├───────┼───────┬───────┬───────┼───────┼───────┬───────┬───────┤"
Printer.Print "│  复  核 │  財  務 │  電  腦 │  審  核 │  倉  庫 │  驗  收 │  主  管 │  經  辦 │"
Printer.Print "├───────┼───────┼───────┼───────┼───────┼───────┼───────┼───────┤"
Printer.Print "│       │       │       │       │       │       │       │       │";
Printer.FontSize = 9
Printer.Font.Bold = True
Printer.Font = "標楷體"
Printer.CurrentX = 11000
Printer.Print user_name
Printer.FontSize = 9
Printer.Font.Bold = True
Printer.Font = "新細明體"
Printer.Print "│       │       │       │       │       │       │       │       │"
Printer.Print "│       │       │       │       │       │       │       │       │"
Printer.Print "│   月  日│   月  日│   月  日│   月  日│   月  日│   月  日│   月  日│   月  日│"
Printer.Print "└───────┴───────┴───────┴───────┴───────┴───────┴───────┴───────┘"
Printer.NewPage
End Sub
需要說明的是表格內的字型為全形字
wumylove1234 2004-09-18
  • 打赏
  • 举报
回复
楼上的,你这种代码,是不是测试要很久才能确定呢?

为什么不用相对的方式.用绝对的方式,调试很烦的吧?
星羽 2004-09-18
  • 打赏
  • 举报
回复
jtkk 说的因该可以啊
星羽 2004-09-18
  • 打赏
  • 举报
回复
。。。看看啊
simonlee2003 2004-09-17
  • 打赏
  • 举报
回复
ryuginka(除了我谁敢用真名:刘银华)说的对,一定要捆绑数据源
jtkkjtkk 2004-09-16
  • 打赏
  • 举报
回复
有这个工夫,用Printer对象早打出来了,决对可以精确定位,完全控制任何一个细节。
这是我才用的一段代码:
Dim asngColWidth(0 To 9) As Single '表格各列的宽度
asngColWidth(0) = 15#: asngColWidth(1) = 24#
asngColWidth(2) = 31#: asngColWidth(3) = 10#
asngColWidth(4) = 15#: asngColWidth(5) = 19#
asngColWidth(6) = 22#: asngColWidth(7) = 16#
asngColWidth(8) = 18#: asngColWidth(9) = 18#

Private Sub PrintXY(oDest As Object, X As Single, Y As Single, strText As String)
oDest.CurrentX = X
oDest.CurrentY = Y
oDest.Print strText
End Sub

'以MM为单位
'X,Y 所画表格的位置,RowCnt 表格的行数,RowHeight 表格的行高,ColWidths()数组,存放每一列的列宽
Private Sub DrawTable(oDest As Object, X As Single, Y As Single, RowCnt As Long, RowHeight As Single, ColWidths() As Single)
Dim sngTableW As Single
Dim sngTableH As Single

Dim lngLoop As Long
Dim lngColCnt As Long

lngColCnt = UBound(ColWidths)
For lngLoop = 0 To lngColCnt
sngTableW = sngTableW + ColWidths(lngLoop)
Next lngLoop

sngTableH = RowCnt * RowHeight

'画表格外边框,用粗线
oDest.DrawWidth = 2
oDest.Line (X, Y)-Step(sngTableW, sngTableH), , B

'画表格内部线条,用细线
oDest.DrawWidth = 1
'画横线
For lngLoop = 1 To RowCnt - 1
oDest.Line (X, Y + lngLoop * RowHeight)-Step(sngTableW, 0)
Next lngLoop

'画竖线
Dim sngXPos As Single
sngXPos = X
For lngLoop = 0 To lngColCnt - 1
sngXPos = sngXPos + ColWidths(lngLoop)
oDest.Line (sngXPos, Y)-Step(0, RowCnt * RowHeight)
Next lngLoop

End Sub

Private Function GetXPosInCell(CellWidth As Single, TextWidth As Single, Align As String) As Single
Select Case Align
Case "C"
GetXPosInCell = (CellWidth - TextWidth) / 2
Case "L"
GetXPosInCell = 1
Case "R"
GetXPosInCell = CellWidth - TextWidth - 1
End Select
End Function



Private Sub PrintInCellXY(oDest As Object, Y As Single, CellLeft As Single, CellWidth As Single, ByVal strText As String, strAlign As String)
Dim sngCellXpos As Single
Dim sngTextWidth As Single
If strAlign = "R" Then strText = Format(strText, "0.00")
sngTextWidth = oDest.TextWidth(strText)
Select Case strAlign
Case "C"
sngCellXpos = (CellWidth - sngTextWidth) / 2
Case "L"
sngCellXpos = 1
Case "R"
sngCellXpos = CellWidth - sngTextWidth - 1
End Select
sngCellXpos = sngCellXpos + CellLeft
oDest.CurrentX = sngCellXpos
oDest.CurrentY = Y
oDest.Print strText
End Sub


zhujiechang 2004-09-16
  • 打赏
  • 举报
回复
可以啊,ado可以支持虚拟的数据集,将你的数据形成数据集绑定.这样就解决了.
ryuginka 2004-09-16
  • 打赏
  • 举报
回复
楼主。可以打印出来的。不过不关怎样,你必须有个数据源,否则打印不出来
yelang771 2004-09-16
  • 打赏
  • 举报
回复
up
jtkkjtkk 2004-09-16
  • 打赏
  • 举报
回复
打印机的初始化部门
sngPaperW = 240 '纸张高度
sngPaperH = 140 '纸张宽度
sngLMarg = 25 '左边距
sngRMarg = 25 '右边距
sngTMarg = 10 '上边距
sngBmarg = 10 '下边距

'打区域的右边界
sngRLimit = sngPaperW - sngLMarg - sngRMarg

Dim asngColWidth(0 To 9) As Single '表格各列的宽度
asngColWidth(0) = 15#: asngColWidth(1) = 24#
asngColWidth(2) = 31#: asngColWidth(3) = 10#
asngColWidth(4) = 15#: asngColWidth(5) = 19#
asngColWidth(6) = 22#: asngColWidth(7) = 16#
asngColWidth(8) = 18#: asngColWidth(9) = 18#

Dim astrCaption(0 To 9) As String '表格的列头
astrCaption(0) = "编 号": astrCaption(1) = "品 名"
astrCaption(2) = "型 号 规 格": astrCaption(3) = "单位"
astrCaption(4) = "需求数量": astrCaption(5) = "计划单价"
astrCaption(6) = "计划金额": astrCaption(7) = "实领数量"
astrCaption(8) = "实际单价": astrCaption(9) = "实际金额"

Dim astrAlign(0 To 9) As String '表头的对齐方式

With Printer
.ScaleMode = 6 '以毫米为单位
.Width = sngPaperW
.Height = sngPaperH

.ScaleTop = -sngTMarg
.ScaleLeft = -sngLMarg
sngYPos = 0
End With

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧