pq scan
Question:
Hi, I want toadd some barcode image as user control to MS Excel in my VSTO project. Can you give me some suggestion?
---- Thomas
Hi, I want toadd some barcode image as user control to MS Excel in my VSTO project. Can you give me some suggestion?
---- Thomas
Hi, Thomas.
There is a simple example for how to insert a barcode control to Excel worksheet using C#.
First, you need create a barcode user control as below:
public partial class BarcodeControl : UserControl { public Barcode _barcode; public BarcodeControl() { InitializeComponent(); _barcode = new Barcode(); } protected override void OnPaint(PaintEventArgs e) { _barcode.Data = "123456"; _barcode.BarType = BarCodeType.Code128; _barcode.Width = this.Width; _barcode.Height = this.Height; Bitmap bmp = _barcode.CreateBarcode(); e.Graphics.DrawImage(bmp, 0, 0); } }
Then, add this barcode control into worksheet.
//get current showing sheet Worksheet worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet); //get current range Excel.Range range = (Excel.Range)Globals.ThisAddIn.Application.Selection; //add barcode control to current range Microsoft.Office.Tools.Excel.ControlSitedynamicControl = worksheet.Controls.AddControl(barControl, range, "barcode");
Hope the C# code can be helpful.
---- pqScan Support Team
Copyright © pqScan 2010-2023. All Rights Reserved.