How to Add Barcode Image to MS Excel in C# ?

back to home  >  Tech FAQ  >  How to Add Barcode Image to MS Excel in C# ?


Hi, is there a way to insert barcode image into Excel? I'm developing an Excel add-in project using C#, and it's to require adding some barcode to the Excel worksheet. Your barcode creator can generate barcode image well, but how can I insert it to Excel?

---- Nelson


Hi, Nelson.

According to Microsoft Office standard, most objects like picture, chart and line, belong to the Shape object in the sheet. So you can use the AddPicture method to insert barcode image to the sheet.

Please note that, AddPicture method can only add image at the disk, so you need save the barcode image to the disk firstly.

//generate barcode image and save it to disk
Barcode barcode = new Barcode();
barcode.BarType = BarCodeType.QRCode;
barcode.Data = "barcode123456";
barcode.Width = barcode.Height = 200;

//add barcode image from disk to current sheet
Excel.Workbookbook1 = Globals.ThisAddIn.Application.ActiveWorkbook;
Excel.Worksheetsheet1 = (Excel.Worksheet)book1.ActiveSheet;
Excel.Range range = (Excel.Range)sheet1.Application.Selection;

sheet1.Shapes.AddPicture(@"c:\barcode.bmp", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, range.Left, range.Top, 200, 200);

Hope the C# code can be helpful.

---- pqScan Support Team

Online Demo Download Trial How to Encode QR Code with Chinese Words in C# ? How to Insert Barcode Control to MS Excel WorkSheetin C# ? How can I Create Barcode to Crystal Report in Visual Studio ? Can I Read Barcode in PDF document using C#? Can I Get a Compression Jpeg Image from PDF ? Merge A Group of Multi-page Tiff to PDF documentusing C#? Translate JPG Image to PDF document in C#? Convert specific pages from PDF to images in C# Is it available for reading all of the barcode in a picture by one time? Do You Support Translate Images to PDF from SQL Database? Question about Image Size.