Documents for Excel, Java Edition Documentation
Features / Barcodes / Code128
In This Topic
    Code128
    In This Topic

    The Code 128 barcode is a linear barcode that represents high-density linear symbology to encode text, numbers, various functions and the entire 128 ASCII character set (from ASCII 0 to ASCII 128). It is widely used in enterprise internal management, production process, logistics control system of the bar code system.

    The below image displays Code128 barcode in a PDF document.

    Code128

    Formula definition

    You can set Code128 in a worksheet using the following formula:

    =BC_CODE128(value, color, backgroudColor, showLabel, labelPosition, codeSet, fontFamily, fontStyle, fontWeight, fontTextDecoration, fontTextAlign, fontSize, quietZoneLeft, quietZoneRight, quietZoneTop, quietZoneBottom)

    Parameter

    Name Description
    value A string that represents encode on the symbol of QRCode.
    color A color that represents the barcode color. The default value is 'rgb(0,0,0)'.
    backgroundColor A color that represents the barcode backgroundcolor. The default value is 'rgb(255, 255, 255)'
    showLabel Specifies whether to show label text when the barcode has label.
    labelPosition ?A value that represents the label position when the label is shown.
    codeSet A value that represents which code is set to use for QRCode. It has 'auto|A|B|C' values. The default value is 'auto'.
    fontFamily A string that represents the label text fontFamily. The default value is 'sans-serif'.
    fontStyle A string that represents the label text fontStyle. The default value is 'normal'.
    fontWeight A string that represents the label text fontWeight. The default value is 'normal'.
    fontTextDecoration A string that represents the label text fontTextDecoration. The default value is 'none'.
    fontTextAlign A string that represents the label text fontTextAlign. The default value is 'center'.
    fontSize A string that represents the label text fontSize. The default value is '12px'.
    quietZoneLeft A value that represents the size of left quiet zone.
    quietZoneRight A value that represents the size of right quiet zone.
    quietZoneTop A value that represents the size of top quiet zone.
    quietZoneBottom A value that represents the size of bottom quiet zone.

    Using Code

    This example code sets Code128 in the worksheet.

    Java
    Copy Code
    // Create a new workbook
    Workbook workbook = new Workbook();
    // Set worksheet layout and data
    IWorksheet worksheet = workbook.getWorksheets().get(0);
    worksheet.getRange("B:F").setColumnWidth(20);
    worksheet.getRange("4:7").setRowHeight(60);
    worksheet.getRange("A:A").setColumnWidth(5);
    worksheet.getRange("B2").setValue("Code128");
    worksheet.getRange("B2:F2").setMergeCells(true);
    worksheet.getRange("B3:F3")
            .setValue(new Object[][] { { "Name", "Number", "Default", "Hidden Label", "Custom Label Font" } });
    worksheet.getRange("B4:C7").setHorizontalAlignment(HorizontalAlignment.Center);
    worksheet.getRange("B4:C7").setVerticalAlignment(VerticalAlignment.Center);
    worksheet.getRange("B2:F3").setHorizontalAlignment(HorizontalAlignment.Center);
    worksheet.getRange("B2:F3").setVerticalAlignment(VerticalAlignment.Center);
    worksheet.getRange("B4:C7")
            .setValue(new Object[][] { { "Police", 911 }, { "Telephone Directory Assistance", 411 },
                    { "Non-emergency Municipal Services", 311 }, { "Travel Info Call 511", 511 } });
    worksheet.getRange("B4:C6").setWrapText(true);
    worksheet.getRange("G6").setWrapText(true);
    worksheet.getPageSetup().setOrientation(PageOrientation.Landscape);
    worksheet.getPageSetup().setPrintGridlines(true);
    // Set formula
    for (int i = 4; i < 8; i++) {
        worksheet.getRange("D" + i).setFormula("=BC_CODE128" + "(C" + i + ")");
        worksheet.getRange("E" + i).setFormula("=BC_CODE128" + "(C" + i + ", , , false))");
        worksheet.getRange("F" + i)
                .setFormula("=BC_CODE128" + "(C" + i + ", , , true, \"top\", \"B\",\"Arial\", \"normal\")");
    }
    
    // Save to an pdf file
    workbook.save("Code128.pdf");