Document Solutions for Excel, Java Edition | Document Solutions
Features / Barcodes / EAN-8
In This Topic
    EAN-8
    In This Topic

    EAN-8 barcode is used on small packages where an EAN-13 barcode would be too large. Similar to EAN-13, EAN-8 uses only numeric characters and a check digit. This barcode accepts only seven numbers as a string to calculate a check digit (CheckSum) and add it to the eighth position. The check digit is an additional digit that can be used to verify that the barcode has been scanned accurately.

    The below image displays EAN-8 barcode in a PDF document.

    EAN-8 barcode

    Formula definition

    You can set EAN-8 barcode in a worksheet using the following formula:

    =BC_EAN8(value, color, backgroundColor, showLabel, labelPosition, fontFamily, fontStyle, fontWeight, fontTextDecoration, fontTextAlign, fontSize, quietZoneLeft, quietZoneRight, quietZoneTop, quietZoneBottom)

    Parameter

    Name Description
    value Specifies that the value length must be 7 or 8.
    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.
    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 EAN-8 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:G").setColumnWidth(17);
    worksheet.getRange("4:7").setRowHeight(60);
    worksheet.getRange("A:A").setColumnWidth(5);
    worksheet.getRange("B2").setValue("EAN-8");
    worksheet.getRange("B2:F2").setMergeCells(true);
    worksheet.getRange("B3:G3").setValue(new Object[][] {
            { "Name", "Number", "Default", "Change showLabel", "Change labelPosition", "Explain" } });
    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:C6").setValue(new Object[][] { { "Value length is 7", "4137962" },
            { "Value length is 8", "81424863" }, { "value length is 8", "81424865" } });
    worksheet.getRange("G6")
            .setValue("No EAN-8 generated, because the last digit is check-sum digit and it is invalid");
    worksheet.getRange("G6").getFont().setColor(Color.GetRed());
    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 < 7; i++) {
        worksheet.getRange("D" + i).setFormula("=BC_EAN8" + "(C" + i + ")");
        worksheet.getRange("E" + i).setFormula("=BC_EAN8" + "(C" + i + ",,,0)");
        worksheet.getRange("F" + i).setFormula("=BC_EAN8" + "(C" + i + ",,,,\"top\")");
    }
    
    // Save to an pdf file
    workbook.save("EAN8.pdf");