Documentazione HotXLS

AddTable metodo

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 sul lato XLSX, così il codice agnostico rispetto al formato può chiamare la stessa firma. (Disponibile dalla v2.33.0.)

Sintassi

funzione 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 e 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. Testo di intestazione per colonna. Deve contenere esattamente tanti elementi quanto è largo l'intervallo

Osservazioni

The new table is added to the worksheet's Tables collection. Its StyleName defaults to 'TableStyleMedium2' e ShowRowStripes defaults to True, matching what Excel e 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). I salvataggi BIFF5 non sono interessati (le tabelle sono un concetto BIFF8+). Il record LIST12 memorizza StyleName e 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 e field-level AutoFilter metadata into FEAT11

Esempio

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;

Vedere also