HotXLS Docs

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:

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

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:

See also