TX Sheet Control

Barcodes and QR Codes

Topic

Barcodes display a cell value, a formula result or a literal payload as a machine-readable symbol. Insert them inside a cell or over the worksheet as a movable drawing. A barcode in a cell retains that cell's underlying value or formula.

Insert from the Ribbon

Select a cell, then choose Insert → Barcode or Insert → QR Code in the Illustrations group. These commands always insert a new code. If a cell or floating barcode is already selected, the dialog defaults to a separate floating object. Choose the placement and value source, inspect the live preview and choose Apply. The Appearance section contains the symbology, colors and QR correction settings. Size controls use CSS pixels.

For Place in Cell, the destination field identifies the owning cell. For Place Over Cells, the selected cell provides the initial position, so there is no destination field. The Selected Cell source option creates an explicit binding to that cell; moving the object retains this binding. Choose another cell or formula, or enter a literal value, to use different data.

Barcode settings with a live QR preview

The dialog keeps its size as you switch sections. Only one section is open at a time. Changes remain a draft until Apply. Click an in-cell barcode to select its owning cell and show its selection outline. Right-click it for Barcode Settings or Remove Barcode, or double-click to edit it. Removing a cell barcode retains its underlying value or formula. Floating barcodes also support double-click editing and Barcode Settings in their context menu.

Supported Formats

SymbologyAPI valuePayload
Code 128code128ASCII characters 0–127, with automatic code-set switching
Code 39code39Uppercase letters, digits, spaces and -.$/+%
EAN-13ean1312 digits, or 13 including a valid check digit
EAN-8ean87 digits, or 8 including a valid check digit
UPC-Aupca11 digits, or 12 including a valid check digit
UPC-Eupce6, 7 or 8 digits; number system 0 or 1
Interleaved 2 of 5itfAn even number of digits
CodabarcodabarNumeric and supported punctuation data enclosed by uppercase A–D start/stop characters
QR Code Model 2qrCodeUTF-8 text, including Unicode

Missing EAN and UPC check digits are generated; supplied check digits are validated. Linear payloads have a limit of 512 characters and must also meet their symbology's rules. QR versions range from 1 through 40. Omit the version to select the smallest that fits; capacity depends on the version and correction level. Correction defaults to M and accepts L, M, Q or H.

Bind a Cell or Floating Object

In the browser, use editor.workbook; in a Node.js application, use the server control's workbook. Run this example against an existing workbook:

const sheet = book.sheets.at(0);
sheet.cell('A2').setText('00012345');
// The same cell keeps its text and displays it as Code 128.
sheet.cell('A2').setBarcode({ symbology: 'code128' });
sheet.columns.at(0).setWidth({ pixels: 300 });
sheet.rows.at(1).setHeight({ pixels: 100 });

// Another cell reads a formula result.
sheet.cell('B2').setBarcode({
    symbology: 'qrCode',
    source: '="https://example.com/orders/"&A2',
    errorCorrection: 'H'
});
sheet.columns.at(1).setWidth({ pixels: 160 });

// A floating object uses the same live source.
const barcode = sheet.drawings.addBarcode({
    symbology: 'qrCode',
    source: '=A2',
    anchor: { cell: 'D2' },
    size: { width: 160, height: 160 },
    name: 'Order QR'
});
sheet.cell('A2').setText('00098765'); // Both dependent symbols update.

source accepts references and formulas from the workbook's calculation engine, including qualified references such as ='Orders'!A2 and structured table references. Values supplied by a data connector or mail merge work through the same cells. The source must produce the value in the workbook; a barcode does not fetch URLs or external data by itself.

Do not combine source with value. Omit both to read the owning cell, or the anchor cell of a floating object. Sources use raw calculated values rather than formatted display text. Store identifiers as text to retain leading zeros, or use a text-producing formula. Empty values show no symbol. Invalid dynamic data shows an error indicator until corrected; invalid nonempty literal payloads reject insertion.

Use cell.setBarcode() to remove the cell barcode without clearing its value. Use barcode.updateBarcode(options) to replace all floating barcode settings while retaining its object identity and geometry. Floating barcodes support the ordinary drawing move, size, copy, rotation and removal operations.

Merge Repeating Labels

Mail merge writes each record's values first. Barcode sources then resolve against the merged cells. A repeating block copies cell barcodes and floating barcodes anchored inside the block, translating relative source references for each record. Absolute references retain their normal spreadsheet meaning.

const labels = book.sheets.add('Order Labels');
labels.range('A1:C1').setValues([['Order', 'Cell QR', 'Floating QR']]);
labels.columns.at(0).setWidth({ pixels: 300 });
labels.columns.at(1).setWidth({ pixels: 160 });
labels.rows.at(1).setHeight({ pixels: 160 });
labels.cell('A2').setText('ORDER').setBarcode({ symbology: 'code128' });
labels.cell('B2').setBarcode({ symbology: 'qrCode', source: '=A2' });
labels.drawings.addBarcode({
    symbology: 'qrCode', source: '=A2', anchor: { cell: 'C2' },
    size: { width: 150, height: 150 }
});
book.setMailMerge({
    version: 1,
    bindings: [],
    repeatBlocks: [{
        id: 'orders', sheetId: labels.id, source: 'orders',
        templateRange: 'A2:C2',
        fields: [{ cell: 'A2', path: 'number', type: 'string' }]
    }]
});
const template = book.createMailMergeTemplate();
const result = await template.merge({
    orders: [{ number: '000001' }, { number: '000002' }]
});
const pdf = await result.workbook.save(StreamType.PDF);

Import StreamType from the applicable browser or server package. The result contains two independent labels; the template workbook is unchanged. Empty repeat data removes the corresponding floating barcode instances. The Razor sample's /Barcodes page demonstrates nine formats, live sources and three repeating order labels. See Mail Merge for scalar bindings and merge policies.

Use the .NET API

Use these methods on a worksheet from an existing ServerSheetControl session:

var sheet = await control.Workbook.Sheets.AtAsync(0);
await sheet.Cell("A2").SetTextAsync("00012345");
await sheet.Cell("A2").SetBarcodeAsync(new BarcodeOptions
{
    Symbology = "code128"
});
var drawing = await sheet.Drawings.AddBarcodeAsync(new BarcodeDrawingOptions
{
    Symbology = "qrCode",
    Source = "=A2",
    Anchor = new DrawingAnchor("D2"),
    Size = new ObjectSize(160, 160)
});
await sheet.Cell("A2").SetTextAsync("00098765");
var pdf = await control.SaveAsync(StreamType.PDF);

The types belong to TXTextControl.TXSheetControl.Server. Use GetBarcodeAsync to read settings, UpdateBarcodeAsync to replace a floating object's settings and SetBarcodeAsync(null) to remove a cell barcode. The existing mail merge API preserves the same source bindings in merged sessions.

Rendering and File Compatibility

Barcodes use native encoders without a barcode font, external service or network request. Screen and PDF rendering use vector modules. SVG and PNG helpers are available for applications that need a standalone symbol: encodeBarcode, renderBarcodeSVG, renderBarcodePNG and barcodeCheckDigit.

Default colors are black on white. Linear codes include a human-readable caption by default; QR codes do not. Quiet zones remain part of the rendered symbol. Keep adequate contrast and size, and scan representative printed labels on the intended printer and scanner.

The internal workbook format preserves live settings and source bindings. XLSX stores Excel-compatible pictures plus TX metadata; reopening with TX Sheet Control restores the bindings and retained underlying cell values. Excel displays the exported pictures but does not regenerate barcodes when a source changes. A third-party save may remove custom metadata, so retain the internal workbook as the live template.

Barcodes share the picture limits of 200 cell pictures and 200 floating pictures and shapes per worksheet, with the existing image-data budget. Plan larger label batches across worksheets or documents.

See Also