TXLSXTable / TXLSXTables classes
Excel-style table band (the "Insert > Table" feature in Excel).
Tables apply a built-in style, a filter row, and a structured name to a
rectangular range. The collection lives on
TXLSXWorksheet.Tables;
SaveAs writes each table to xl/tables/tableN.xml (workbook-
global numbering) and binds it through the worksheet rels file. Open
parses the relationship and the table body back into the collection.
Declaration
type
TXLSXTable = class
constructor Create;
procedure Assign(Source: TXLSXTable);
property Id: Integer; // assigned by SaveAs
property Name: WideString;
property DisplayName: WideString;
property Range: WideString; // e.g. "A1:C10"
property Columns: TStringList; // header text per column
property StyleName: WideString; // e.g. "TableStyleMedium2"
property ShowFirstColumn: Boolean;
property ShowLastColumn: Boolean;
property ShowRowStripes: Boolean;
property ShowColumnStripes: Boolean;
end;
TXLSXTables = class
function Add: TXLSXTable; overload;
function Add(const AName, ARange: WideString;
AColumns: TStrings): Integer; overload;
procedure Clear;
property Count: Integer;
property Items[Index: Integer]: TXLSXTable; default;
end;
Worksheet shortcut
TXLSXWorksheet exposes
AddTable(Name, Range, AColumns: TStrings) which forwards to
Tables.Add.
Example
var
cols: TStringList;
begin
ws.Cells.Item[1, 1].Value := 'Name';
ws.Cells.Item[1, 2].Value := 'Region';
ws.Cells.Item[1, 3].Value := 'Sales';
// ... rows below ...
cols := TStringList.Create;
try
cols.Add('Name');
cols.Add('Region');
cols.Add('Sales');
ws.AddTable('SalesTable', 'A1:C5', cols);
finally
cols.Free;
end;