翻譯|使用教程|編輯:黃竹雯|2018-10-23 10:55:14.000|閱讀 649 次
概述:本系列教程會解答您在使用條形碼生成控件TBarCode SDK產品時遇到的絕大部分疑惑。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
TBarCode SDK是一款可以在任意應用程序和打印機下生成和打印所有條碼的條碼軟件組件。TBarCode SDK對于Microsoft® Office 用戶以及軟件開發者提供條碼打印。使用此款條碼軟件組件您可以以完美效果生成和打印所有用于工業和商業條碼符號。
示例代碼:
Dim barcodeShape As InlineShape ' switch to design mode (optional) ' ActiveDocument.ToggleFormsDesign ' Insert bar code object at actual position in document Set barcodeShape = Selection.InlineShapes.AddOLEControl(ClassType:="TBarCode10.TBarCode10.1") ' change size barcodeShape.Width = 200 barcodeShape.Height = 100 ' adjust bar code properties programmatically barcodeShape.OLEFormat.Object.Barcode = 20 ' 20 = Code-128 barcodeShape.OLEFormat.Object.Text = "Hello"
“AddOLEControl”函數接受第二個參數,該參數可以是放置條形碼控件的Range對象。
請使用此代碼段作為起點:
Barcode.Barcode = eBC_PDF417 Barcode.Text = "My Data... " ' the following settings produce a barcode 82,296 mm wide ' if your barcode should have a constant width, set the data columns ' as shown below (increase/decrease to make wider/smaller symbol) Barcode.PDF417.Columns = 15 Dim X, Y Dim Scaling Dim Dpi ' define ratio of module width (small bar width) to row height X = 1 Y = 1 ' keeps default ratio, which is 1:3 'Y = 3 / 2 ' creates 1:5 ratio Dpi = 300 ' 300 dpi printer Scaling = 3 ' 1 Module (smallest bar) = 3 Pixels = 0.254mm Dim Cols Dim Rows Cols = Barcode.Get2DXCols() Rows = Barcode.Get2DXRows() Dim XSize Dim YSize XSize = Int(X * Cols) YSize = Int(Y * Rows) ' scale with DPI enlarging factor XSize = XSize * Scaling YSize = YSize * Scaling ' Save barcode as bitmap Barcode.SaveImage "c:\temp\barcode.bmp", eIMBmp, XSize, YSize, Dpi, Dpi
必須離開設計模式才能保護文檔。如果插入條形碼控件,則文檔將切換到設計模式。通過Control Toolbox您可以離開設計模式,然后您就可以保護文檔。
請使用此代碼段作為起點:
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long Dim obj As New TBarCode10 Dim nWidth As Long Dim nHeight As Long Dim dc As Long With obj .BarCode = eBC_DataMatrix .DataMatrix.Size = eDMSz_32x32 .Text = myData .QuietZoneUnit = eMUModules .QuietZoneBottom = 2 .QuietZoneLeft = 2 .QuietZoneTop = 2 .QuietZoneRight = 2 .ModuleWidth = "508" .SizeMode = eSizeMode_CustomModuleWidth .Dpi = 1440 / Screen.TwipsPerPixelX ' screen resolution in dpi dc = CreateCompatibleDC(0) ' screen DC nWidth = .BCWidthHdc(dc, 96, 96, eMUPixel) + 0.9999 ' module width should be set nHeight = .BCHeightHdc(dc, 96, 96, eMUPixel) + 0.9999 ' module width should be set .CopyToClipboardEx dc, nWidth, nHeight, "" DeleteDC(dc) End With
您可以更改鏈接單元格或條形碼控件的內容,然后直接從VBA中打印。但是你看到條形碼控件仍然包含舊值。原因是Excel在打印之前不會向ActiveX控件發送重繪命令(如果在VBA中完成)。這是Excel中的錯誤。
有一種強制重繪對象的解決方法,您需要在VBA中以編程方式處理每個條形碼ActiveX控件并在打印前更改其大小。然后由Excel重新繪制。
'redraw a single barcode object by adressing it through its instance name Dim origValue origValue = TBarCode101.Width TBarCode101.Width = origValue + 1 TBarCode101.Width = origValue
' redraw all ActiveX Controls on the current sheet Sub UpdateOLEControls() Dim myShape As shape Dim counter As Integer Dim origWidth As Single For counter = 1 To ActiveSheet.Shapes.Count Set myShape = ActiveSheet.Shapes(counter) If (myShape.Type = msoOLEControlObject) Then ' resize => force redraw origWidth = myShape.Width myShape.Width = origWidth + 1 myShape.Width = origWidth End If Next counter End Sub
要將功能字符FNC1添加到條形碼數據,請按以下步驟操作:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn