XLSX Facade Overview (lxHandleX)
lxHandleX is the dedicated facade unit for Excel 2007+ (.xlsx)
file format support. It coexists with the original lxHandle facade
so that legacy code keeps working without any changes:
lxHandle— primary facade for the Excel 97-2003 BIFF format (.xls), HTML, RTF, CSV, and TSV exports. All existing user code continues to use this unit unchanged.lxHandleX— primary facade for the Excel 2007+ OOXML format (.xlsx). Provides its own workbook and worksheet types so XLSX-specific behavior (theme colors, shared strings, styles, comments and drawings) is not retrofitted onto the BIFF code path.
Class hierarchy
The XLSX facade exposes the following classes:
type
TXLSXWorkbook = class // top-level workbook with SaveAs / Open
TXLSXSheets = class // worksheet collection on the workbook
TXLSXFonts = class // workbook-level font palette
TXLSXFont = class // single font descriptor
TXLSXFills = class // workbook-level fill palette
TXLSXFill = class // single fill (pattern + fg/bg color)
TXLSXBorders = class // workbook-level border palette
TXLSXBorder = class // four edges + diagonal border
TXLSXNumberFormats = class // workbook-level custom format codes
TXLSXDefinedNames = class // workbook-level named ranges
TXLSXWorksheet = class // single worksheet with cells and decorations
TXLSXCells = class // cell collection on the worksheet
TXLSXCell = class // single cell (value, formula, *Index style refs)
TXLSXMergedCells = class // merged-range collection
TXLSXHyperlinks = class // hyperlink collection
TXLSXComments = class // cell-comment collection
TXLSXImages = class // image collection (drawings + media)
TXLSXConditionalFormats = class // conditional formatting rules
TXLSXDataValidations = class // data-validation rules
TXLSXTables = class // Excel-style table collection
TXLSXCharts = class // chart collection (anchored or full-page)
TXLSXChart = class // single chart (column / bar / line / pie)
TXLSXRichText = class // per-run rich-text payload for cells
TXLSXAlignment = class // cell alignment / wrap / indent / rotation
TXLSXExternalLinks = class // external workbook link collection
TXLSXExternalLink = class // single external workbook reference (Target URL + SheetNames)
These classes are independent of lxHandle.TXLSWorkBook and
lxHandle.IXLSWorksheet. Applications that need both formats may
use both facades side by side:
uses
lxHandle, // XLS / HTML / RTF / CSV workbook (TXLSWorkBook)
lxHandleX; // XLSX workbook (TXLSXWorkbook)
Quick start
The XLSX facade follows the same call-shape conventions as the BIFF
facade — SaveAs / Open on the workbook,
Sheets.Add / Sheets[i] on the worksheet
collection, and Cells.Item[Row, Col].Value on the cell
collection. The example below writes a small workbook that exercises every
currently-supported feature:
uses lxHandleX;
var
wb: TXLSXWorkbook;
ws: TXLSXWorksheet;
bold, yellow, box, currency: Integer;
begin
wb := TXLSXWorkbook.Create;
try
bold := wb.Fonts.Add('Calibri', 12, True, False);
yellow := wb.Fills.AddSolid($FFFFFF00);
box := wb.Borders.AddBox(xlsxBorderThin);
currency := wb.NumberFormats.Add('"$"#,##0.00');
ws := wb.Sheets.Add('Demo');
ws.Cells.Item[1, 1].Value := 'Hello';
ws.Cells.Item[1, 1].FontIndex := bold + 1;
ws.Cells.Item[1, 2].Value := 123.45;
ws.Cells.Item[1, 2].NumberFormatIndex := currency + 1;
ws.Cells.Item[2, 1].Value := Now; // tagged as date
ws.Cells.Item[2, 2].Formula := 'SUM(B1:B1)';
ws.Cells.Item[3, 1].FillIndex := yellow + 1; // highlight cell
ws.Cells.Item[3, 2].BorderIndex := box + 1; // boxed cell
ws.ColWidth[1] := 24;
ws.RowHeight[1] := 28;
ws.MergeCells(4, 1, 4, 3);
ws.AddHyperlink(5, 1, 'https://www.loslab.com', 'Visit losLab');
ws.AddComment(5, 2, 'Important note', 'Kevin');
ws.AddImageFromFile(6, 1, 'logo.png');
ws.AddConditionalFormat('B1:B10', xlsxCfOpGreaterThan, '100');
ws.AddListValidation('C1:C5', 'Yes,No,Maybe');
wb.DefinedNames.Add('SalesData', 'Demo!$A$1:$B$10');
wb.SaveAs('demo.xlsx');
finally
wb.Free;
end;
end;
Supported features
- Cell values: numbers, booleans, strings, dates, formulas.
- Shared strings table (
xl/sharedStrings.xml) with deduplication on the write path. - Workbook-level style palettes —
Workbook.Fonts,Fills,Borders, andNumberFormats— plus per-cellFontIndex/FillIndex/BorderIndex/NumberFormatIndex. SaveAs emits real<fonts>/<fills>/<borders>/<numFmts>+<cellXfs>blocks; Open parses them back so Name/Size/Bold/Italic/Color, fill patterns, border edges, and custom number formats all survive the round-trip. - Per-column widths via
Worksheet.ColWidth[Col]and per-row heights viaWorksheet.RowHeight[Row](worksheet<cols>block and per-<row>htattributes). - Built-in date
cellXfat indexXlsxXfIndexDate;TDateTimevalues are tagged automatically. - Merged cells (
<mergeCells>). - Hyperlinks (
<hyperlinks>) backed by per-worksheet rels for external URLs. - Cell comments with VML drawing (
xl/commentsN.xml+xl/drawings/vmlDrawingN.vml) so balloons render in Excel. - Embedded images (PNG / JPEG / GIF / BMP) via
Worksheet.Images, written toxl/media/imageN.<ext>plus per-sheet drawing XML and rels. - Workbook-level named ranges via
Workbook.DefinedNames(workbook-scoped or sheet-scoped throughSheetIndex). - Per-worksheet conditional formatting
(
Worksheet.ConditionalFormats) and data validation (Worksheet.DataValidations) including the dropdownAddListValidation(Range, Items)shortcut. - Row / column outline groups (
RowOutlineLevel,ColOutlineLevel), hidden state (RowHidden,ColHidden), and collapsed group state (RowCollapsed,ColCollapsed). - Frozen panes via
Worksheet.FreezePane(Col, Row). - Page setup — six margin properties, paper size, orientation,
page scale, fit-to-width / fit-to-height, plus
HeaderText/FooterText. - Auto-filter (
Worksheet.SetAutoFilter). - Excel-style tables (TXLSXTable) with style info and tableColumns.
- Document properties (
Workbook.Title,Author,Subject,Keywords,Description,LastModifiedBy,Company, etc.) written todocProps/core.xml+docProps/app.xml. - Worksheet / workbook password protection (legacy 16-bit hash)
through
Worksheet.Protect/Workbook.ProtectWorkbook; AES encryption API surface (SaveAsEncrypted/OpenEncrypted) reserved for a follow-up release. - VBA project preservation via
Workbook.LoadVbaProjectFromFile/VbaProject; bytes round-trip unchanged. - Charts — column / bar / line / pie via
TXLSXChart, anchored
on a worksheet (
Worksheet.AddChart) or full-page on a dedicated chart sheet viaWorkbook.AddChartSheet(Name, Type, Title). - Rich-text cells via TXLSXRichText with per-run font formatting; round-trips through the shared-string table.
- Internal hyperlink anchors via
Worksheet.AddHyperlinkToCell(Row, Col, "Sheet2!A1")(no rels relationship needed). - Cell range copy / move / clear API on the worksheet
(
CopyRange,CopyRangeTo,MoveRange,ClearRange). - Cell alignment via
TXLSXAlignment +
per-cell
AlignmentIndex. - Worksheet tab color via
Worksheet.TabColor/TabColorIsAuto. - Streaming SaveAs path (
Workbook.StreamingWrite := True) that builds and writes each worksheet without holding the others in memory; the per-row XML accumulator usesTXLSWideStringBuilderso the cell loop stays linear. - Round-trip
Openfor everything above (except AES encryption and chart-sheet sheet identification, which fall back to plain Open / regular worksheet respectively). - Stream-based export and import:
SaveAs(Stream),Open(Stream)for in-memory or BLOB-field use. - Cell protection:
TXLSXCell.LockedandFormulaHidden— control which cells are editable or whose formulas are visible when the sheet is protected. - Auto-fit column width and row height from cell content:
Worksheet.AutoFitColumn,AutoFitColumns,AutoFitRow,AutoFitRows. - Row / column insert and delete with full cascade:
InsertRows,DeleteRows,InsertCols,DeleteCols. Side effects propagate through cells, merged ranges, hyperlinks, comments, freeze pane, and range-string references. - Extended page setup:
PrintArea,PrintTitleRows,PrintTitleCols,PrintGridlines,PrintHeadings,BlackAndWhite,Draft,PrintNotes,PrintOverThenDown. - Sheet visibility:
Worksheet.Visibility(xlsxSheetVisible/xlsxSheetHidden/xlsxSheetVeryHidden) andIsSelected. - Manual page breaks:
AddRowBreak,AddColBreak, query and removal helpers. - Auto-filter column criteria:
Worksheet.AddAutoFilterColumnwith single or AND/OR two-criterion filter rules (TXLSXAutoFilterColumn). - Workbook date base:
Workbook.Date1904switches between the 1900 (Windows default) and 1904 (Mac) date epoch. - Diagonal borders:
TXLSXBorder.DiagonalUpandDiagonalDownenable the diagonal lines; theDiagonaledge carries the style and color. - Extended font properties:
TXLSXFont.VertAlign(superscript / subscript),OutlineFont,Shadow,Family,CharSet. - Named range metadata:
TXLSXDefinedName.HiddenandComment. - Sheet view options:
Worksheet.Zoom,DisplayGridLines,DisplayZeros,DisplayRightToLeft,StandardWidth,StandardHeight. - OOXML legacy indexed-color palette:
Workbook.IndexedColor[0..63]withResetIndexedColors. - External workbook links:
Workbook.ExternalLinks/ TXLSXExternalLink — Target URL + SheetNames metadata round-trip. - Theme color support on
TXLSXFont,TXLSXFill, andTXLSXBorderEdge:ColorTheme/ColorIndex/TintAndShadeproperties with priority ordering (theme > indexed > RGB). - CSV export:
Workbook.SaveAsCSV— 4 overloads (FileName or Stream × active-sheet / explicit SheetIndex + Delimiter), UTF-8 with BOM, RFC 4180 quoting. - HTML export:
Workbook.SaveAsHTML— 4 overloads, HTML5 table with inline CSS styles andcolspan/rowspanfor merged cells. - RTF export:
Workbook.SaveAsRTF— 4 overloads, RTF 1.6 table with column widths, per-cell font formatting, and full-BMP unicode via signed-16-bit\uN?escapes.
Shared infrastructure
Both facades share a common set of lower-level helper units, which means style descriptors, hash tables, AVL trees, ZIP and XML I/O, RGB-to-HLS conversions, and string builders are written once and used by either path. The shared helpers include:
lxStyleXf,lxStyleFont,lxStyleColor,lxStyleFill,lxStyleBorder— modern style descriptorslxRgb— RGB / HLS color conversionlxHashTable,lxList2,lxAvlTree,lxCols,lxRows— deduplicating containers and AVL-backed cell heap building blockslxXmlReader,lxXmlWriter,lxZipArchive— OOXML transport layerlxStrBuilder,lxCacheStream,lxWStream,lxZlibStream— stream and string assembly helpers