HotXLS Docs

其他 XLSX 外观 API 成员

本页介绍 lxHandleX声明的较小公开 API 成员,包括 HTML 导出选项,以及供直接处理 XLSX 单元格引用或 XML 负载文本的调用方使用的辅助函数

公式数组内存限制

property FormulaArrayMemoryLimit: Int64;
      
限制由生成的公式数组分配的载荷,例如 MUNIT本页介绍 Double 声明的一些较小的公共 API 成员,包括 HTML 导出选项,以及为直接处理 XLSX 单元格引用或 XML 负载文本的调用方提供的辅助函数

HTML 导出选项

type
  TXLSXHtmlExportOptions = class
    constructor Create;
    property Title: WideString;
    property WriteDocument: Boolean;
    property IncludeStyles: Boolean;
    property IncludeBOM: Boolean;
    property TableClass: WideString;
  end;
      
Title当 WriteDocument 为 True 时,设置文档标题
WriteDocument为 True 时,写入完整的 HTML 文档。为 False 时,仅写入表格片段
IncludeStyles控制导出的 HTML 是否包含生成的 CSS 和内联样式信息
IncludeBOM控制文件和流输出是否以 UTF-8 BOM 开头
TableClass为生成的 <table> 元素添加一个 CSS 类名

XLSX 引用辅助函数

function XlsxColumnLabel(Col: Integer): WideString;
function XlsxCellRef(Row, Col: Integer): WideString;
function XlsxColumnIndex(const ColumnLabel: WideString): Integer;
function XlsxParseCellRef(const Ref: WideString; out Row, Col: Integer): Boolean;
function XlsxParseRangeRef(const Ref: WideString; out Row1, Col1, Row2, Col2: Integer): Boolean;
      
XlsxColumnLabel将基于 1 的列索引转换为 A1 样式的列标签,例如 A、 Z或 AA
XlsxCellRef根据基于 1 的行号和列号构建 A1 样式的单元格引用
XlsxColumnIndex将 A1 样式的列标签转换为基于 1 的列索引
XlsxParseCellRef解析单个 A1 样式的单元格引用,并返回行和列坐标
XlsxParseRangeRef解析矩形 A1 样式区域,并返回包含两端的、基于 1 的边界

XLSX XML 转义辅助函数

function XlsxEscapeText(const Value: WideString): WideString;
function XlsxEscapeAttr(const Value: WideString): WideString;
      
XlsxEscapeText 转义 XML 文本节点内容,而 XlsxEscapeAttr 转义 XML 属性值,并保留 Excel 必须精确读回的属性空白

示例

本帮助文件各处记载的高级 XLSX 成员传递并返回以下简单类型,声明于 lxHandleX

{ Find and replace }
TXLSXFindFlag = (lxfMatchCase, lxfWholeCell, lxfSearchFormulas,
  lxfUseWildcards, lxfBackward, lxfByColumns);
TXLSXFindOptions = set of TXLSXFindFlag;
TXLSXReplaceAction = (raReplace, raSkip, raAbort);
TXLSXReplaceEvent = function(ARow, ACol: Integer;
  const ACurrentText: WideString; var ANewText: WideString):
  TXLSXReplaceAction of object;

{ Progress and recalculation policy }
TXLSXProgressPhase = (xlsxProgressReading, xlsxProgressWriting,
  xlsxProgressCalculating, xlsxProgressExporting);
TXLSXProgressState = (ppsBegin, ppsWork, ppsEnd);
TXLSXRecalcMode = (xrmManual, xrmIfDirty, xrmAlways);
TXLSXPasswordEvent = procedure(Sender: TObject;
  var PassWord: WideString) of object;

{ Custom document properties (docProps/custom.xml) }
TXLSXCustomPropType = (xcptText, xcptNumber, xcptDate, xcptBoolean);
TXLSXCustomProperty = class
  Name: WideString;
  PropType: TXLSXCustomPropType;
{ + TextValue, NumberValue, DateValue, BoolValue accessors }
end;

{ Table styles, fills, sorts, external links, controls, sparklines }
TXLSXTableStyleSectionKind = (xltssWholeTable, xltssHeaderRow,
  xltssTotalRow, xltssFirstColumn, xltssLastColumn, xltssFirstRowStripe,
  xltssSecondRowStripe, xltssFirstColumnStripe, xltssSecondColumnStripe,
  xltssFirstHeaderCell, xltssLastHeaderCell, xltssFirstTotalCell,
  xltssLastTotalCell { + subtotal and subheading slots });
TXLSXFillPattern = (xlsxFillNone, xlsxFillSolid, xlsxFillGray125
  { + the remaining ECMA-376 pattern values });
TXLSXGradientKind = (xlsxGradientNone, xlsxGradientLinear, xlsxGradientPath);
TXLSXSortBy = (xlsxBsValue, xlsxBsCellColor, xlsxBsFontColor, xlsxBsIcon);
TXLSXSortMethod = (xlsxSmNone, xlsxSmStroke, xlsxSmPinYin);
TXLSXExternalLinkKind = (xlsxExternalLinkUnknown, xlsxExternalLinkWorkbook,
  xlsxExternalLinkDde { + the remaining link kinds });
TXLSXFormControlType = (xfcButton, xfcCheckBox, xfcRadioButton, xfcComboBox,
  xfcListBox);
TXLSXSparklineAxisType = (xlsxSparklineAxisIndividual,
  xlsxSparklineAxisGroup, xlsxSparklineAxisCustom);
TXLSXSparklineEmptyCells = (xlsxSparklineEmptyGap, xlsxSparklineEmptyZero,
  xlsxSparklineEmptySpan);

{ Chart authoring and layout }
TXLSXChartBarGrouping = (xlsxBarGroupClustered, xlsxBarGroupStacked,
  xlsxBarGroupPercentStacked);
TXLSXChartMarkerSymbol = (xlsxMarkerAuto, xlsxMarkerCircle, xlsxMarkerDash,
  xlsxMarkerDiamond, xlsxMarkerDot, xlsxMarkerPlus, xlsxMarkerSquare,
  xlsxMarkerStar, xlsxMarkerTriangle, xlsxMarkerX, xlsxMarkerNone);
TXLSXChartDataLabelPos = (xlsxDlblPosDefault, xlsxDlblPosCenter,
  xlsxDlblPosInEnd, xlsxDlblPosOutEnd, xlsxDlblPosBestFit, xlsxDlblPosLeft,
  xlsxDlblPosRight, xlsxDlblPosTop, xlsxDlblPosBottom);
TXLSXChartMutable = class;     { mutable base of the chart model nodes }
TXLSXChartLayoutRect = record
  Left, Top, Right, Bottom: Double;
end;
TXLSXChartResolvedLayout = record
  ChartRect: TXLSXChartLayoutRect;
  TitleRect: TXLSXChartLayoutRect;
  LegendRect: TXLSXChartLayoutRect;
  PlotOuterRect: TXLSXChartLayoutRect;
  PlotInnerRect: TXLSXChartLayoutRect;
  { + per-axis title rectangles and visibility flags }
end;

{ Pagination keep-together blocks }
TXLSXKeepTogetherRange = record
  Row1, Row2: Integer;
  Level: Integer;
  ReplaceBiggerLevels: Boolean;
end;
TXLSXKeepTogetherCols = record
  Col1, Col2: Integer;
  Level: Integer;
  ReplaceBiggerLevels: Boolean;
end;

{ Diagnostics records }
TXLSXValidationIssue = record
  Row, Col: Integer;
  ValidationIndex: Integer;
  Reason: WideString;
end;
TXLSXUnknownFunctionInfo = record
  Sheet: Integer;
  Row, Col: Integer;
  Name: WideString;
  LocationKind: TXLSFormulaSymbolLocationKind;
  DefinedNameIndex: Integer;
  DefinedName: WideString;
end;
TXLSXRowMajorOrder = record
  CellOrder: array of Integer;
  RowStarts: array of Integer;
  MaxRow: Integer;
end;
      
Find and replaceTXLSXWorksheet.FindText / FindTextIn 接受 TXLSXFindOptions (区分大小写、整单元格、搜索公式、通配符、向后搜索、按列搜索); ReplaceText 接受 TXLSXReplaceEvent ,其结果针对每个匹配选择 raReplace、 raSkip或 raAbort ,并可通过可写的 ANewText 进行逐单元格替换
Progress and savingTXLSXWorkbook.OnProgress / OnProgressEx 传递 TXLSXProgressPhase 和(扩展形式的)带 TXLSXProgressState 标志的 Abort ; RecalcBeforeSave 是 TXLSXRecalcMode ,选择序列化之前手动重算、仅重算脏单元格还是总是重算; OnPassword 是提供打开密码和写入密码的 TXLSXPasswordEvent that supplies open and write passwords
Custom propertiesTXLSXWorkbook.CustomProperties 是 TXLSXCustomProperties 集合,提供类型化的 AddText / AddNumber / AddDate / AddBoolean 创建方法,以及 FindByName、 Delete、 Clear和 Count 、 Items 枚举;每个 TXLSXCustomProperty 用与 ECMA-376 variant 映射匹配的 TXLSXCustomPropType 标记其值
Style overlaysTXLSXStyleOverlays 管理在已存储样式之上的按区域覆盖: Add 创建覆盖, ApplyToCell 重新设置单个单元格的样式, Resolve、 ResolveRowDefault和 ResolveColumnDefault 在加载期间响应样式查询, HasVirtualStyle 报告生成的样式, MaxVirtualRow 限制虚拟行, ApplyStructuralEdit 在行或列编辑后平移覆盖, Clear、 Count和 Items 维护集合
Styles, fills, and overlaysTXLSXFill 通过 Pattern、 GradientKind和 GradientStops 暴露 TXLSXFillPattern、 TXLSXGradientKind和 TXLSXGradientStop; TXLSXWorksheet.StyleOverlays 是 TXLSXStyleOverlays 集合,其 TXLSXStyleOverlay 条目携带矩形、受影响的格式部分和覆盖用的单元格样式
Tables, sorts, and links自定义表格样式(TXLSXWorkbook.CustomTableStyles)用 TXLSXTableStyleSectionKind 槽位构建分区格式:集合提供 Add、 FindByName、 Delete、 Clear、 Count和 Items,每个 TXLSXCustomTableStyle 暴露 Name、 SectionSize、 PivotStyle和 TableStyleFlag ,并响应 HasSection / ResolveSection 查询;排序条件用 TXLSXSortBy 划分键类型、用 TXLSXSortMethod决定文本排序方式; TXLSXExternalLink.Kind 是 TXLSXExternalLinkKind ,每个链接列出带 TXLSXExternalDefinedName 和 Name 的 RefersTo
Custom XML partsTXLSXWorkbook.CustomXmlParts 保留项特定的自定义 XML: Add、 Delete和 Clear 维护这些部件;每个 TXLSXCustomXmlPart 在 Xml 中携带负载,外加一个 ItemId 和一个保存架构关系的 SchemaRefs 字符串列表(AddSchemaRef 追加);被保留的部件在保存时原样 Roundtrip
Cell style payloadsTXLSXCellStylePayload 是附加到单个单元格的可共享不可变样式包: Acquire / Release 管理引用计数, Clone 复制它, IsDefault 测试默认样式, InternKey 标识相等的负载以便存储去重
Controls, drawings, and sparklinesTXLSXWorksheet.FormControls 是 TXLSXFormControls 对象的 TXLSXFormControl 集合——每个对象暴露 ControlType、 Caption、 MacroName、 LinkedCell及其 Items 列表——由 TXLSXFormControlType分类, TXLSXFormControlItems 保存每个控件的项文本;绘图对象通过 TXLSDrawingObjectKind报告其种类,迷你图组通过 TXLSXSparklineAxisType 和 TXLSXSparklineEmptyCells
Charts绘图组和序列用 TXLSXChartBarGrouping、 TXLSXChartMarkerSymbol和 TXLSXChartDataLabelPos 枚举划分条形分组、标记符号和数据标签位置;图表模型节点共享 TXLSXChartMutable 基类, TXLSXChartLayoutResolver.ResolveChart 为图表、标题、图例、绘图区和坐标轴标题填充由 TXLSXChartResolvedLayout 矩形组成的 TXLSXChartLayoutRect 矩形(图表、标题、图例、绘图区和坐标轴标题)
Pagination keep blocksKeepRowsTogether / KeepColumnsTogether 维护 TXLSXKeepTogetherRange 和 TXLSXKeepTogetherCols 记录,让分页规划把一个块保持在同一页上
DiagnosticsTXLSXWorksheet.CheckDataValidations 返回 TXLSXValidationIssue 记录(单元格、验证索引、原因); TXLSXWorkbook.ScanUnknownFunctions 返回 TXLSXUnknownFunctionInfo 记录,定位单元格和已定义名称中未实现的调用; TXLSXCells.GetStorageStatistics 用单元格、行块、逐负载字节和带样式空白单元格的统计填充 TXLSXCellStorageStatistics 记录; TXLSXWorksheet.BuildRowMajorCellOrder 返回描述已填充单元格内存遍历顺序的 TXLSXRowMajorOrder ,描述已填充单元格的内存遍历顺序
TXLSXWorkbook.FormulaLocale 读取或写入解析和序列化公式时使用的区域设置标记,与经典工作簿的公式区域处理保持一致

表格 Slicer

Table slicers (Excel 2013+) are written and inspected through two collections: TXLSXWorksheet.Slicers holds the per-sheet slicer views (TXLSXSlicer) and TXLSXWorkbook.SlicerCaches holds the shared data sources (TXLSXSlicerCache)

property TXLSXWorksheet.Slicers: TXLSXSlicers;
property TXLSXWorkbook.SlicerCaches: TXLSXSlicerCaches;

{ TXLSXSlicers }
function Add(ATable: TXLSXTable; const AColumnName: WideString): TXLSXSlicer; overload;
function Add(ATable: TXLSXTable; const AColumnName: WideString;
  ARow1, ACol1, ARow2, ACol2: Integer): TXLSXSlicer; overload;
function IndexByName(const AName: WideString): Integer;
function FindByName(const AName: WideString): TXLSXSlicer;
procedure Delete(Index: Integer);
procedure Clear;
property Count: Integer;
property Items[Index: Integer]: TXLSXSlicer;

{ TXLSXSlicer view }
property Name: WideString;          { workbook-unique }
property CacheName: WideString;
property Cache: TXLSXSlicerCache;
property Caption: WideString;
property StartItem: Integer;
property ColumnCount: Integer;
property ColumnWidth: WideString;
property ShowCaption: Integer;
property StyleName: WideString;
property LockedPosition: Integer;
property RowHeight: WideString;
property RowHeightEmu: Integer;
procedure SetBounds(ARow1, ACol1, ARow2, ACol2: Integer);
property FromRow, FromCol, ToRow, ToCol: Integer;   { anchor cell corners }
property FromRowOff, FromColOff, ToRowOff, ToColOff: Integer; { EMU offsets }
property AnchorType: TXLSXAnchorEditAs;
property HasAnchor: Boolean;

{ TXLSXSlicers, load-path entry }
function AddInternal: TXLSXSlicer;

{ TXLSXSlicerCache }
property Name: WideString;          { e.g. Slicer_Region }
property SourceName: WideString;    { source table column / pivot field }
property IsTableCache: Boolean;
property IsPivot: Boolean;
property IsNonOlapPivot: Boolean;
property ItemCount: Integer;
property ItemCacheIndex[Index: Integer]: Integer;
property ItemSelected[Index: Integer]: Boolean;
function SetSelectedItems(const CacheItemIndices: array of Integer): Integer;
function ClearSelection: Integer;
property TableId: Integer;
property TableColumnId: Integer;
property SortOrder: WideString;     { '' | ascending | descending }
property CrossFilter: WideString;   { '' | none | showItemsWithDataAtTop | showItemsWithNoData }
property CustomListSort: Integer;   { -1 absent, else 0/1 }

{ TXLSXSlicerCaches }
function Add: TXLSXSlicerCache;
function FindByName(const AName: WideString): TXLSXSlicerCache;
function IndexOfName(const AName: WideString): Integer;
function FindForTableColumn(ATableId, ATableColumnId: Integer): TXLSXSlicerCache;
procedure Delete(Index: Integer);
procedure Clear;
property Count: Integer;
property Items[Index: Integer]: TXLSXSlicerCache;
      

Slicers.Add(Table, ColumnName) builds a slicer end to end: it registers or reuses the backing cache named Slicer_<column>, reserves the matching #N/A defined name, writes the worksheet slicerList 扩展名,并用一个标记兼容性绘图锚点固定视图,其回退提示可覆盖旧版 Excel;第二个重载固定视图矩形,否则使用表格右侧的默认锚点

已加载的视图和缓存会在打开时重新解析,共享缓存在多个视图之间复用,删除某个缓存的最后一个视图会丢弃该缓存;无法识别的属性和扩展保留其原始表示,表格绑定跟踪保存后的表格 id,受支持的数据透视表连接跟踪保存后的工作表标识

受支持的导入非 OLAP 数据透视表缓存通过 IsNonOlapPivot、 ItemCount、 ItemCacheIndex、 ItemSelected、 SetSelectedItems和 ClearSelection 暴露类型化的成员检查与受保护的选择变更;共享视图行为、失败原子性和导入的同字段掩码边界参见 数据透视表 Slicer 选择

不受支持的数据透视表缓存保留其原始字节;从文件加载的 Slicer 视图也可以作为绘图对象通过 TXLSXDrawingObject.Slicer 访问

示例

var
  Ref: WideString;
  Row, Col: Integer;
begin
  Ref := XlsxCellRef(10, 5);
  if XlsxParseCellRef(Ref, Row, Col) then
    Worksheet.Cells.Item[Row, Col].Value := 'Checked';
end;
    

I/O 回调、序列化器样式池、加密文件验证和工作区依赖图契约参见 工作簿基础设施 API