39条形码制作的一种办法

来源:互联网 发布:网络空间治理 网警 编辑:程序博客网 时间:2024/04/29 18:04
   最近,在图书馆管理系统,需要把图书编号以条形码打印出来。 上网查找了一下,大概有这几种制方法:
 
  1、CODE39码的编码规则,直接划线。
        1.1 每五条线表示一个字符;    
       1.2 粗线表示1,细线表示0;    
       1.3线条间的间隙宽的表示1,窄的表示0;    
       1.4五条线加上它们之间的四条间隙就是九位二进制编码,而且这九位中必定有三位是1,所以称为39码;   
       1.5条形码的首尾各一个*标识开始和结束    
  
          strBarTable(0)   =   "001100100"     '   0    
   
    strBarTable(1)   =   "100010100"     '   1    
   
    strBarTable(2)   =   "010010100"     '   2    
   
    strBarTable(3)   =   "110000100"     '   3    
   
    strBarTable(4)   =   "001010100"     '   4    
   
    strBarTable(5)   =   "101000100"     '   5    
   
    strBarTable(6)   =   "011000100"     '   6    
   
    strBarTable(7)   =   "000110100"     '   7    
   
    strBarTable(8)   =   "100100100"     '   8    
   
    strBarTable(9)   =   "010100100"     '   9    
   
    strBarTable(10)   =   "100010010"  '   A    
   
    strBarTable(11)   =   "010010010"  '   B    
   
    strBarTable(12)   =   "110000010"  '   C    
   
    strBarTable(13)   =   "001010010"  '   D    
   
    strBarTable(14)   =   "101000010"  '   E    
   
    strBarTable(15)   =   "011000010"  '   F    
   
    strBarTable(16)   =   "000110010"  '   G    
   
    strBarTable(17)   =   "100100010"  '   H    
   
    strBarTable(18)   =   "010100010"  '   I    
   
    strBarTable(19)   =   "001100010"  '   J    
   
    strBarTable(20)   =   "100010001"  '   K    
   
    strBarTable(21)   =   "010010001"  '   L    
   
    strBarTable(22)   =   "110000001"  '   M    
   
    strBarTable(23)   =   "001010001"  '   N    
   
    strBarTable(24)   =   "101000001"  '   O    
   
    strBarTable(25)   =   "011000001"  '   P    
   
    strBarTable(26)   =   "000110001"  '   Q    
   
    strBarTable(27)   =   "100100001"  '   R    
   
    strBarTable(28)   =   "010100001"  '   S    
   
    strBarTable(29)   =   "001100001"  '   T    
   
    strBarTable(30)   =   "100011000"  '   U    
   
    strBarTable(31)   =   "010011000"  '   V    
   
    strBarTable(32)   =   "110001000"  '   W    
   
    strBarTable(33)   =   "001011000"  '   X    
   
    strBarTable(34)   =   "101001000"  '   Y    
   
    strBarTable(35)   =   "011001000"  '   Z    
   
    strBarTable(36)   =   "000111000"  '   -    
   
    strBarTable(37)   =   "100101000"  '   %    
   
    strBarTable(38)   =   "010101000"  '   $    
   
    strBarTable(39)   =   "001101000"  '   *

  2、第二使用第三方控件,直接生成相应的图片,然后存储到临时库,再制作成报表。
 
   3、使用条形码字体,直接制作报表。

   认真想了一下,他妈的,时间太紧了,一个半月一个人要出图书馆管理系统。没有时间自己写个组件去画。使用第三方控件,生成的效果不如意,不够灵活。我果断地采用了第三种办法。

   条形码大小,字体大小,条形码行高,字体行高。打印列数,列宽都要设置成用户自定义。使用水晶报表难以实现。想了一下,我采用了,在程序里生成Excel文件的形式,用户随心所欲了。

  以下是预览效果:
 
 报表效果:

 
代码:
Private Sub CreateExcel()

        
If mDst.Tables(0).Rows.Count = 0 Then Exit Sub


        
Dim objApp As New Excel.Application
        
Dim objBook As Excel.Workbook
        
Dim objWorkSheel As Excel.Worksheet



        
Try

            
Dim strPath As String

            objBook 
= objApp.Workbooks.Add
            objWorkSheel 
= objBook.Worksheets(1)

            objWorkSheel.PageSetup.LeftMargin 
= 1.2   '左边距
            objWorkSheel.PageSetup.CenterHorizontally = True '居中

            
Dim intColumn As Integer
            
Dim intRow As Integer
            intColumn 
= 1
            intRow 
= 1

            
Dim dataRow As DataRow
            
For Each dataRow In mDst.Tables(0).Rows

                
If intColumn <= mColumn Then

                    objWorkSheel.Range(
GetChar(intColumn) & intRow).VerticalAlignment = Excel.XlVAlign.xlVAlignCenter  '对齐方式
                    objWorkSheel.Range(GetChar(intColumn) & intRow).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter


                    objWorkSheel.Cells(intRow, intColumn).Font.Name 
= "3 of 9 Barcode"  '条形码字体设置
                    objWorkSheel.Cells(intRow, intColumn).Font.Size = mBarcodeBig
                    objWorkSheel.Range(
GetChar(intColumn) & intRow).ColumnWidth = mWidth
                    objWorkSheel.Range(
GetChar(intColumn) & intRow).RowHeight = mBarCodeHiegth
                    objWorkSheel.Range(
GetChar(intColumn) & intRow).Value = dataRow("BookCode")


                    objWorkSheel.Range(
GetChar(intColumn) & intRow + 1).VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
                    objWorkSheel.Range(
GetChar(intColumn) & intRow + 1).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter


                    objWorkSheel.Range(
GetChar(intColumn) & intRow + 1).Font.Name = "宋体"
                    objWorkSheel.Cells(intRow 
+ 1, intColumn).Font.Size = mFontBig
                    objWorkSheel.Range(
GetChar(intColumn) & intRow + 1).ColumnWidth = mWidth
                    objWorkSheel.Range(
GetChar(intColumn) & intRow + 1).RowHeight = mFontHiegth

                    objWorkSheel.Range(
GetChar(intColumn) & intRow + 1).Value = dataRow("BookCode")

                
End If

                
If intColumn = mColumn Then
                    intColumn 
= 1
                    intRow 
+= 2
                
Else
                    intColumn 
+= 1
                
End If

            
Next


            objApp.Visible 
= True

            objApp 
= Nothing


        
Catch ex As Exception
            MessageBox.Show(
"生成条码信息时发生错误!" & vbCrLf & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
            objBook 
= Nothing
            objApp 
= Nothing
        
End Try
    
End Sub
原创粉丝点击