Creating Barcodes in Excel with Python and Fonts (PREVIEW)
Python in Excel
Announced by Microsoft in 2023, Python in Excel enables users to build advanced analytical capabilities directly within Excel by leveraging one of the world’s most popular programming languages in the age of Artificial Intelligence. Python calculations are securely executed in the Microsoft Cloud, and the results are seamlessly returned to the Excel worksheet. Compared to traditional VBA (Visual Basic for Applications) macros, Python in Excel offers a key advantage — it allows spreadsheets to be saved locally as .xlsx files without requiring macro-enabled .xlsm formats. This provides organizations with a safer and more compliant environment while still empowering users to run sophisticated data analysis and visualization models.
Python Barcode Formulas
Since 2005, ConnectCode has provided barcode generation capabilities in Excel using VBA Barcode Formulas and barcode fonts. This allows users to generate barcodes in bulk directly within Excel — where their data resides — without relying on third-party label software. The same functionality is now available in Python in Excel, offering full backward compatibility with the barcode fonts used to display the generated barcodes.
Advantages
Using Python in Excel offers numerous advantages, including advanced analytics and machine learning capabilities. When applied to barcode generation, its key benefit is that no local installation is required — all Python calculations run securely in Microsoft’s cloud. This enables workbooks to remain macro-free, avoiding potential security warnings within an organization. Python’s results can be returned as either Python objects or Excel values, allowing seamless integration with barcode fonts to produce GS1/ISO-compliant barcodes directly in Excel.
Testimonials
Tutorial: Creating a Code 128 Barcode with Python in Excel and Barcode Fonts
Prerequisites
- Python in Excel is available to Microsoft 365 Enterprise, Business, and Family/Personal (Preview) users, as well as in Excel for the web.
- ConnectCode Barcode Fonts for Windows or Mac.
- Python in Excel Barcode Formulas / Sample Spreadsheets.
If you are already familiar with Python in Excel and comfortable using Python formulas, you may skip ahead and use the provided sample spreadsheets.
Instructions (Windows)
1. Launch Microsoft Excel. Enter sample data for generating a Code 128 barcode.
2. Download and unzip the PythonInExcelBarcode.zip package.
NOTE - Before continuing, ensure that Python is enabled in Excel. Go to the Formulas tab and confirm that Python options such as the Editor are available. You can also test this by typing =PY( in any cell—if Python is active, the cell will display a green indicator. If it does not, make sure Python in Excel is activated before proceeding.
3. Open the file Code128Auto.txt using Notepad (or any text editor), select all (Ctrl+A), and copy (Ctrl+C). In Excel, select cell F1 and enter =PY(.Paste the copied formula and press Ctrl+Enter.The Python code will be parsed securely in Microsoft Cloud. If you see an error, ensure your version of Excel supports Python in Excel. On successful parsing, the cell will display “None” without errors.
4. In cell B2, enter =PY( and, when the green PY indicator appears, type: encode_code128auto(xl("A2")) Press Ctrl+Enter to execute the formula. The barcode data will be returned to the cell.
5. Right-click cell A2, then choose “Excel Value” for “Python Output.” This converts the Python result into a normal Excel value that can be formatted with a barcode font.
6. Apply the barcode font:
- Choose CCode128_S3 (or CCode128_S3_Trial).
- Set the font size to 25.
A GS1-compliant barcode should now appear.
7. Copy the formula down from B2 to B6 to generate additional barcodes. You have now successfully created barcodes in Excel using Python and ConnectCode Barcode Fonts. These barcodes can be submitted to GS1 for audit and verification.
Instructions (Mac)
1. Launch Microsoft Excel. Enter sample data for generating a Code 128 barcode.
2. Download and unzip the PythonInExcelBarcode.zip package.
3. Open the file Code128Auto.txt using TextEdit, select all (Command+A), and copy (Command+C). In Excel, select cell F1, enter =PY(, paste the copied formula, and press Control+Enter. The Python code will be parsed in Microsoft Cloud. If errors occur, check that you are using the correct version of Excel that supports Python in Excel. On success, the cell will display “None” without errors.
4. In cell B2, enter: =PY(encode_code128auto(xl("A2"))) Then press Control+Enter to execute.
5. Right-click cell A2 and select “Excel Value” for “Python Output.” This converts the result to a standard cell value.
6. Apply the barcode font:
- Choose CCode128_S3 (or CCode128_S3_Trial).
- Set the font size to 25.
A GS1-compliant barcode should now appear.
7. Drag down the cell to replicate the formula for additional rows (e.g., B3–B6). You have now generated barcodes in Excel using Python and ConnectCode Barcode Fonts.
Note: Python in Excel is not supported on iPad or iPhone. Please use Excel for Mac.
Download
Python In Excel Barcode Formulas
- PythonInExcelBarcode.zip - Windows / macOS
Barcode Fonts
See the Reasons why many companies choose our barcode fonts package.
- ConnectCodeFreeSetup.Exe - Free Barcode Fonts for Windows
- ConnectCodeTrialSetup.Exe (Trial) - Full Trial Barcode Fonts Package for Windows
- ConnectCode Barcode Software and Fonts for Mac
TIP - After the installation, you will need to Restart Excel so that it can pick up the newly installed fonts. Simply save your spreadsheet and restart Excel.
Print Barcode Labels
- Print Barcode & Label on Apple devices - macOS/iOS/visionOS
- Print Barcode & Label on Windows devices - Windows 10/11
Why use Barcode Fonts and not just Barcode Images?
When a font is printed, it rasters to the resolution of the printer and will not be limited to the DPI (Dots per Inch) of the computer screen. You will only need to make sure your printer is of high resolution and will definitely not have problems when scanning the printed barcodes. The high quality barcodes produced using fonts also allows us to help you meet with all industry compliance requirements.
Supported Barcode Formats and Python Formulas
Unless stated otherwise, the second parameter in the Python formulas below specifies whether to include a barcode check digit — use 1 to enable it and 0 to disable it.
NOTE - In Excel, all Python formulas must begin with =PY(. This indicates to Excel that the following expression should be executed using Python rather than standard Excel functions. Without this prefix, Excel will not recognize or run the Python code.
NOTE - Click on the barcode to see the font required.
- Codabar – AIM-BC3-2000
encode_codabar(xl("A2")) - Code39 – ISO/IEC 16388
encode_code39(xl("A2"),1) - Code39 ASCII – ISO/IEC 16388
encode_code39ascii(xl("A2"),1) - Code93 – AIM-BC5-2000
encode_code93(xl("A2"),1) - Code128 Auto – ISO/IEC 15417:2007
encode_code128auto(xl("A2")) - Code128 A – ISO/IEC 15417:2007
encode_code128a(xl("A2")) - Code128 B – ISO/IEC 15417:2007
encode_code128b(xl("A2")) - Code128 C – ISO/IEC 15417:2007
encode_code128c(xl("A2")) - UCC/EAN (GS1-128) – GS1 Standard
encode_uccean(xl("A2"),1) 1 for indicating Strict GS1 Compliance. 0 for legacy compatibility - Interleaved 2 of 5 (I2of5) – ISO/IEC 16390
encode_i2of5(xl("A2"),1) - Industrial 2 of 5
encode_industrial2of5(xl("A2"),1) - ITF-14
encode_itf14(xl("A2"),1,1) The second parameter is used for specifying whether to generate a check digit. The third parameter is used for specifying bearers bar. 1 for Rectangle Bearers Bar and 0 for Top/Bottom Bearers Bar. - Modified Plessy
encode_modified_plessy(xl("A2"),1) - POSTNET
encode_postnet(xl("A2")) - EAN-13 (European Article Number) – ISO/IEC 15420
encode_ean13(xl("A2"),1) The second parameter is used for specifying whether to use the Extended Style. - EAN-8 – ISO/IEC 15420
encode_ean8(xl("A2")) This formula without the second parameter can be used with both Standard and Extended Style barcode fonts. - UPC-A (Universal Product Code) – ISO/IEC 15420
encode_upca(xl("A2"),1) The second parameter is used for specifying whether to use the Extended Style. - UPC-E – ISO/IEC 15420
encode_upce(xl("A2"),1) The second parameter is used for specifying whether to use the Extended Style. - EXT2
encode_ext2(xl("A2")) - EXT5
encode_ext5(xl("A2")) - GS1 DataBar 14 – ISO/IEC 24724:2006
encode_gs1databar14(xl("A2"),0) The second parameter is used for specifying the linkage field. - GS1 DataBar 14 Truncated
encode_gs1databar14_truncated(xl("A2"),0) The second parameter is used for specifying the linkage field.
Which Barcode do I need?
Please see the following Barcode Symbology Guide for a quick start.
Other Excel Barcode Options
Besides using Python in Excel you can also create Excel Barcodes with VBA or an Excel Barcode Add In for Office.
