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 的对应方法,与格式无关的代码因此可以调用相同签名。(v2.33.0 起可用)
语法
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。每一列的标题文本。条目数必须与范围的列数完全一致 |
备注
The new table is added to the worksheet's
Tables collection. Its
StyleName defaults to
'TableStyleMedium2' and
ShowRowStripes 默认为 True,与 Excel 和 XLSX 侧的产出一致。若不设置,id(每个工作表 1..N)会在保存时分配
BIFF8 emits the FEATHEADR11 / FEAT11 / LIST12 record group only on SaveAs(xlExcel97)。BIFF5 保存不受影响(Table 是 BIFF8+ 的概念)。LIST12 记录存储 StyleName 以及镶边行 / 镶边列标志,使用 MS-XLS 表样式客户端布局。从 v2.33.2 起,工作表级 AUTOFILTERINFO / AUTOFILTER 记录会在同一工作表上的 Table 完全覆盖自动筛选范围时被省略,因为 Excel 把自动筛选内嵌在 Table 对象自身内部;v2.87.4 还会把对应的表级和字段级 AutoFilter 元数据写入 FEAT11
示例
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;
请参阅