前提1,报表直接用现成的。不需要做改动。条码(不是二维码)仅仅是一种字体,跟宋体,黑体之类的一样的。当然细节还是有点差别的。但也别怕。
前提2,下载条码字体:Code 128.ttf
一、进入报表服务器。随便找个目录,比如桌面。把下载好的 Code128.ttf 文件复制进来,进行安装。
1.1、Win Vista\Win 7\Win 8\Win10系统:鼠标右键单击字体文件,然后点击 > “Install” 安装字体
1.2、Windows XP(2000\98)\server 2008\server 2012等系统:把解压好的字体文件放入 C:\Windows\Fonts 目录中即可
二、打开需要显示的报表,在水晶报表里的【字段资源管理器】的【公式字段】中新建一个公式字段。点击【使用编辑器】之后弹出【公式工作室】。
三、在【公式工作室】中的【报表自定义函数】新建一个函数 比如: GetCode128B,在代码框中输入如下代码(VB代码):
输入名称后,选择中间的 使用编辑器
把代码复制进去:
Function GetCode128B( strIn As string ) As String
Dim intLoop As Number
Dim intPosition as Number
Dim intTotalVal as Number
Dim strOut as String
Dim strSpChr as String
Dim strEndChr as String
Dim intEndNo as Number
strOut = ""
for intLoop = 0 to Len(strIn) - 1
intPosition = intLoop + 1
strSpChr = Mid(strIn, intPosition, 1)
intTotalVal = intTotalVal + (Asc(strSpChr) - 32) * intPosition
next
intTotalVal = intTotalVal + 104
intTotalVal = intTotalVal mod 103
If intTotalVal >= 95 Then
Select Case intTotalVal
Case 95
strEndChr = "Ã"
Case 96
strEndChr = "Ä"
Case 97
strEndChr = "Å"
Case 98
strEndChr = "Æ"
Case 99
strEndChr = "Ç"
Case 100
strEndChr = "È"
Case 101
strEndChr = "É"
Case 102
strEndChr = "Ê"
End Select
Else
intTotalVal = intTotalVal + 32
strEndChr = Chr(intTotalVal)
End If
GetCode128B= "Ì" + strIn + strEndChr + "Î"
End Function
保存。
点击新建的公式字段,在自定义函数选择框内,选择刚新建的自定义函数。在【函数参数】的【值】中选择你要转换的数据库字段。
拖字段到报表相应的位置,并设置合适的字体大小,把字体改成 code128 条码的字体
效果如下
转载请注明:赫非域 » TIPTOP 水晶报表打印条码code128