HotXLS Docs

AddTable method

Attaches a BIFF8 Table (Excel ListObject) to a cell range, returning the new TXLSTable object so additional properties (StyleName, banded-row flags, TotalsRowShown) can be tuned before save. The shape mirrors TXLSXWorksheet.AddTable on the XLSX side so format-agnostic code can call the same signature. (Available since v2.33.0.)

Syntax

function AddTable(const AName, ARange: WideString; AColumns: TStrings): TXLSTable;
AName WideString. The structured-reference table name shown in Excel's Name Box, e.g. 'SalesTable'. Becomes both Name and DisplayName on the returned object.
ARange WideString. The cell range the Table covers in A1 notation, e.g. 'A1:D10'. The first row of the range is treated as the header row.
AColumns TStrings. Header text per column. Must contain exactly as many entries as the range is wide.

Remarks

The new table is added to the worksheet's Tables collection. Its StyleName defaults to 'TableStyleMedium2' and ShowRowStripes defaults to True, matching what Excel and the XLSX side produce. The id (1..N per sheet) is assigned at save time if you do not set it.

BIFF8 emits the FEATHEADR11 / FEAT11 / LIST12 record group only on SaveAs(xlExcel97). BIFF5 saves are unaffected (Tables are a BIFF8+ concept). The LIST12 record stores StyleName and the banded-row / banded-column flags using the MS-XLS table-style client layout. From v2.33.2 the sheet-level AUTOFILTERINFO / AUTOFILTER records are suppressed when a Table on the same sheet fully covers the autofilter range, because Excel embeds the autofilter inside the Table object itself; v2.87.4 also writes the corresponding table-level and field-level AutoFilter metadata into FEAT11.

Example

This example writes a four-column sales region bound as a Table at A1:D10.

var
  cols: TStringList;
begin
  cols := TStringList.Create;
  try
    cols.Add('Region');
    cols.Add('Product');
    cols.Add('Quarter');
    cols.Add('Revenue');
    Sheet.AddTable('SalesTable', 'A1:D10', cols);
  finally
    cols.Free;
  end;

See also