TXLSTable / TXLSTables classes
单元:lxHandle
BIFF8 (.xls) 表(Excel ListObjects)。表把一个命名的结构化引用区域连同内置样式和内嵌自动筛选附加到矩形范围。该集合位于 TXLSWorksheet.Tables; use AddTable as the most common entry point. The shape mirrors TXLSXTable / TXLSXTables (XLSX 侧也有对应方法),因此向工作簿添加表的代码可以与格式无关。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 and returns the new table
object so you can refine its StyleName or banded-row flags
before save
Save-time behavior
On BIFF8 SaveAs(xlExcel97),工作表会发出一个 FEATHEADR11 ($0871) 表特性头,然后每个表发出一个 FEAT11 ($0872) TableFeatureType 负载,外加工作表 EOF 之前、工作表保护之后的一个 LIST12 ($0877) 样式记录。从 v2.87.4 起,LIST12 样式记录使用 MS-XLS
List12TableStyleClientInfo layout, including the banded
row / column flags and the style name as an XLUnicodeString
HotXLS 不再为表元数据发出遗留的 FEATHEADR ($0867) 记录。不含表的工作簿保存行为与之前完全一致,也不带任何表记录流开销。BIFF5 保存不受影响,因为 Table 是 BIFF8+ 的概念
From v2.33.2 the BIFF8 writer also suppresses the standalone
sheet-level AUTOFILTERINFO / AUTOFILTER
记录会在同一工作表上的 Table 完全覆盖自动筛选范围时被省略,因为 Excel 把自动筛选下拉内嵌在 Table 对象自身内部。从 v2.87.4 起,表自身的 Feature11
元数据还会设置表级和字段级 AutoFilter 标志,并发出空的逐列 Feat11FdaAutoFilter blocks
Excel expects for table filter dropdowns
示例
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);
请参阅
TXLSWorksheet.AddTable 方法
TXLSWorksheet.Tables 属性
TXLSXTable / TXLSXTables (XLSX side)