Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1704
  • 博文数量: 1
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 20
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-26 09:52
文章分类
文章存档

2018年(1)

我的朋友
最近访客

分类: Windows平台

2018-09-15 00:56:48

1、首先准备 16字符针式串口打印机+USB转串口线, 自己淘宝搜。



2、安装串口程序,这个打印机是通过串口传输数据的。

3、安装USB转串口线的驱动程序。

4、通过excel的vba 开发自动计算功能及 批量打印算法。

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub print_onlyone()
Dim MSComm1
Set MSComm1 = CreateObject("MSCOMMLib.MSComm") '首先创建一对象
    
MSComm1.CommPort = CInt(Sheet2.Cells(1, 2))            '占用的串口号,1表示COM1
 MSComm1.Settings = "9600,N,8,1" '这个自己根据自己的情况设置
MSComm1.RThreshold = 1
 MSComm1.InputLen = 0

MSComm1.InputMode = comInputModeText
 MSComm1.RTSEnable = True
 MSComm1.InBufferCount = 0

If MSComm1.PortOpen = False Then
 MSComm1.PortOpen = True  '这句话放到连接按钮事件中去
End If
Dim tmp As String
'开始打印
MSComm1.Output = Chr$(27) & Chr$(64)   '重新初始化打印机

MSComm1.Output = Chr$(27) & Chr$(49) & Chr$(5)            ' 没年月日的行距  5 line

'一行 16个字符
MSComm1.Output = Space16(Sheet2.Cells(2, 2))              ' 向端口发送指令  电话:
MSComm1.Output = Convert(Sheet2.Cells(2, 2))
MSComm1.Output = Chr$(13)

MSComm1.Output = Space16(Sheet2.Cells(3, 2))             ' 向端口发送指令  车号:
MSComm1.Output = Convert(Sheet2.Cells(3, 2))
MSComm1.Output = Chr$(13)

MSComm1.Output = Space16(Sheet2.Cells(4, 2))    ' 向端口发送指令  证号:
MSComm1.Output = Convert(Sheet2.Cells(4, 2))
MSComm1.Output = Chr$(13)

MSComm1.Output = Space16(Sheet2.Cells(5, 2))    ' 向端口发送指令  日期:
MSComm1.Output = Convert(Sheet2.Cells(5, 2))
MSComm1.Output = Chr$(13)

MSComm1.Output = Space16(Sheet2.Cells(6, 2))    ' 向端口发送指令  上车时间:
MSComm1.Output = Convert(Sheet2.Cells(6, 2))
MSComm1.Output = Chr$(13)

MSComm1.Output = Space16(Sheet2.Cells(7, 2))     ' 向端口发送指令  下车时间:
MSComm1.Output = Convert(Sheet2.Cells(7, 2))
MSComm1.Output = Chr$(13)
'''''''''''''''''''''''''''''''''''''''''''''''''''''
MSComm1.Output = Space16(Sheet2.Cells(8, 2))      '单价
MSComm1.Output = Convert(Sheet2.Cells(8, 2))                                                                     
MSComm1.Output = Chr$(13)   ''换行

MSComm1.Output = Space16(Sheet2.Cells(9, 2))      '向端口发送指令  里程
MSComm1.Output = Convert(Sheet2.Cells(9, 2))
MSComm1.Output = Chr$(13)
MSComm1.Output = Space16(Sheet2.Cells(10, 2))     '向端口发送指令 时间 00:09:39
MSComm1.Output = Convert(Sheet2.Cells(10, 2))
MSComm1.Output = Chr$(13)

MSComm1.Output = Space16(Sheet2.Cells(11, 2))      '打印总额
MSComm1.Output = Convert(Sheet2.Cells(11, 2))
MSComm1.Output = Chr$(13)    

MSComm1.Output = Space16(Sheet2.Cells(12, 2))
MSComm1.Output = Convert(Sheet2.Cells(12, 2))
MSComm1.Output = Chr$(13)
MSComm1.Output = Space16(Sheet2.Cells(12, 2))
MSComm1.Output = Convert(Sheet2.Cells(12, 2))
MSComm1.Output = Chr$(13)


'打印完,跳过21行不打印
For i = 1 To 15
MSComm1.Output = Chr$(13)
Next i

If MSComm1.PortOpen = True Then '如果串口被打开
MSComm1.PortOpen = False '关闭按钮
End If

End Sub
。。。。。。。。
其他略去,自己研究研究

开发效果图如下:
1、VBA 代码截图

2、自动计算,自动匹配信息库,批量打印界面


3、信息库保存真实有效的信息




阅读(544) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:没有了

给主人留下些什么吧!~~