TX Sheet Control

BarcodeOptions Class

Class
Namespace
TXTextControl.TXSheetControl.Server
Package
TXTextControl.TXSheetControl.Server from the private NuGet feed or the supplied NuGet folder
Assembly
TXTextControl.TXSheetControl.Api.dll
Install
dotnet add package TXTextControl.TXSheetControl.Server .NET 10 and later.
Also in
TXTextControl.TXSheetControl.Blazor as TXTextControl.TXSheetControl.Api.dll
Derived
BarcodeDrawingOptions

Native barcode configuration for cell and floating symbols.

Syntax

public class BarcodeOptions
{
    public string Symbology { get; init; }
    public string? Source { get; init; }
    public string? Value { get; init; }
    public bool? ShowText { get; init; }
    public string? Foreground { get; init; }
    public string? Background { get; init; }
    public string? ErrorCorrection { get; init; }
    public int? Version { get; init; }
}

Remarks

See Barcodes and QR Codes for a complete .NET example, source validation, mail merge and file compatibility.

  • Constructor — Creates settings.

  • Symbology — Required format: code128, code39, ean13, ean8, upca, upce, itf, codabar or qrCode.

  • Source — Cell reference or formula, with an optional leading equals sign. Mutually exclusive with value. Maximum 8192 characters; cannot be blank.

  • Value — Literal payload, mutually exclusive with source. Maximum 8192 characters. Omit both to read the owning or anchor cell.

  • ShowText — Human-readable caption for linear codes; defaults to true. QR codes always omit the caption.

  • Foreground — Six-digit RGB color. Defaults to #000000.

  • Background — Six-digit RGB color. Defaults to #ffffff.

  • ErrorCorrection — QR correction level. Defaults to M.

  • Version — QR version 1–40. Omit to choose the smallest version that fits.

Constructor

public BarcodeOptions()

Creates an instance with the property defaults shown in this reference. Settings are validated when applied to the owning document; result objects obtained from document operations are detached snapshots.

Examples

Create and save a label workbook with the configured barcode settings.

using TXTextControl.TXSheetControl.Server;

static async Task<byte[]> CreateLabelsAsync(ServerSheetControl control)
{
    var sheet = await control.Workbook.Sheets.AtAsync(0);
    await sheet.Cell("A1").SetTextAsync("https://example.com/invoice/1042");
    var options = new BarcodeOptions {
        Symbology = "qrCode", Source = "A1", ShowText = false,
        Foreground = "#163b63", Background = "#ffffff", ErrorCorrection = "M", Version = 3
    };
    await sheet.Cell("B2").SetBarcodeAsync(options);
    await sheet.Cell("D2").SetBarcodeAsync(new BarcodeOptions { Symbology = "code128", Value = "001042", ShowText = true });
    var snapshot = await sheet.Cell("B2").GetBarcodeAsync();
    return await control.SaveAsync(StreamType.SpreadsheetML);
}