TXLSTable / TXLSTables classes
Unità: lxHandle
BIFF8 (.xls) Tables (Excel ListObjects). A table attaches a named structured-reference region with a built-in style e an embedded autofilter to a rectangular range. The collection lives on TXLSWorksheet.Tables; use AddTable as the most common entry point. The shape mirrors TXLSXTable / TXLSXTables sul lato XLSX, così il codice che aggiunge tabelle a una cartella di lavoro può essere agnostico rispetto al formato. Disponibile dalla v2.33.0
Declaration
type
TXLSTable = class
constructor Create;
procedure Assign(Source: TXLSTable);
property Id: Integer; // assigned by SaveAs (1..N per sheet)
property Name: WideString;
property DisplayName: WideString;
property Range: WideString; // e.g. "A1:F9"
property Columns: TStringList; // header text per column
property StyleName: WideString; // default 'TableStyleMedium2'
property ShowFirstColumn: Boolean; // default False
property ShowLastColumn: Boolean; // default False
property ShowRowStripes: Boolean; // default True
property ShowColumnStripes: Boolean; // default False
property TotalsRowShown: Boolean; // default False
end;
TXLSTables = class
function Add: TXLSTable; overload;
function Add(const AName, ARange: WideString;
AColumns: TStrings): Integer; overload;
procedure Delete(Index: Integer);
procedure Clear;
property Count: Integer;
property Items[Index: Integer]: TXLSTable; default;
end;
Worksheet shortcut
TXLSWorksheet
exposes AddTable(AName, ARange, AColumns)
which forwards to Tables.Add e returns the new table
object so you can refine its StyleName o banded-row flags
before save
Save-time behavior
On BIFF8 SaveAs(xlExcel97), il foglio emette una
intestazione di funzionalità tabella FEATHEADR11 ($0871), poi ogni tabella emette un
FEAT11 ($0872) TableFeatureType payload più un record di stile LIST12
($0877) subito prima dell'EOF del foglio di lavoro, dopo la protezione
del foglio. Dalla v2.87.4 il record di stile LIST12 usa il
List12TableStyleClientInfo layout, including the banded
row / column flags e the style name as an XLUnicodeString
HotXLS no longer emits the legacy FEATHEADR ($0867) record for table
metadata. Workbooks without tables save exactly as before e carry no
table record-stream overhead. BIFF5 saves are unaffected because Tables
are a BIFF8+ concept
From v2.33.2 the BIFF8 writer also suppresses the standalone
sheet-level AUTOFILTERINFO / AUTOFILTER
record quando una tabella sullo stesso foglio copre completamente
l'intervallo del filtro automatico, perché Excel incorpora un menu a discesa del filtro automatico
all'interno dell'oggetto tabella stesso. Dalla v2.87.4 la tabella ha il proprio Feature11
metadata also sets the table-level e field-level AutoFilter flags
e emits the empty per-column Feat11FdaAutoFilter blocks
Excel expects for table filter dropdowns
Esempio
var
cols: TStringList;
begin
Sheet.Cells.Item[1, 1].Value := 'Region';
Sheet.Cells.Item[1, 2].Value := 'Product';
Sheet.Cells.Item[1, 3].Value := 'Quarter';
Sheet.Cells.Item[1, 4].Value := 'Revenue';
// ... nine data rows below ...
cols := TStringList.Create;
try
cols.Add('Region');
cols.Add('Product');
cols.Add('Quarter');
cols.Add('Revenue');
with Sheet.AddTable('SalesTable', 'A1:D10', cols) do
begin
StyleName := 'TableStyleMedium2';
ShowRowStripes := True;
end;
finally
cols.Free;
end;
Workbook.SaveAs('SalesTable.xls', xlExcel97);
Vedere also
TXLSWorksheet.AddTable method
TXLSWorksheet.Tables proprietà
TXLSXTable / TXLSXTables (XLSX side)