单元:lxHandleX
表示 a rectangular XLSX worksheet range returned by
TXLSXWorksheet.Range, RCRange,
UsedRange, EntireRow, or
EntireColumn. A range is a lightweight view over its
worksheet; it does not own cell data
Declaration
TXLSXBuiltinCellStyle = (
xbsNormal, xbsGood, xbsBad, xbsNeutral,
xbsCalculation, xbsCheckCell, xbsExplanatoryText, xbsInput,
xbsLinkedCell, xbsNote, xbsOutput, xbsWarningText,
xbsHeading1, xbsHeading2, xbsHeading3, xbsHeading4, xbsTitle, xbsTotal,
xbsAccent1, xbsAccent2, xbsAccent3, xbsAccent4, xbsAccent5, xbsAccent6);
TXLSXRange = class
constructor Create(ASheet: TXLSXWorksheet; ARow1, ACol1, ARow2, ACol2: Integer);
function RefA1: WideString;
function SaveAsHTML(const FileName: WideString): Integer; overload;
function SaveAsHTML(const FileName: WideString; Options: TXLSXHtmlExportOptions): Integer; overload;
function SaveAsHTML(Stream: TStream): Integer; overload;
function SaveAsHTML(Stream: TStream; Options: TXLSXHtmlExportOptions): Integer; overload;
property Sheet: TXLSXWorksheet;
property Row1, Col1, Row2, Col2: Integer;
property RowCount, ColCount: Integer;
procedure SetValue(const V: Variant);
procedure SetFormula(const F: WideString);
function SetArrayFormula(const F: WideString): Integer;
procedure ClearValues;
procedure Clear;
procedure ClearAll;
procedure SetFontIndex(AIdx: Integer);
procedure SetFillIndex(AIdx: Integer);
procedure SetBorderIndex(AIdx: Integer);
procedure SetNumberFormatIndex(AIdx: Integer);
procedure SetAlignmentIndex(AIdx: Integer);
procedure SetNumberFormat(const Fmt: WideString);
procedure SetBorders(Kind: TXLSXBorderEdgeKind; Style: TXLSXBorderStyle); overload;
procedure SetBorders(Kind: TXLSXBorderEdgeKind; Style: TXLSXBorderStyle; Color: LongWord); overload;
procedure SetLocked(ALocked: Boolean);
procedure SetFormulaHidden(AHidden: Boolean);
procedure AutoFitColumns(AMinWidth: Double = 0; AMaxWidth: Double = 0);
procedure AutoFitRows(AMinHeight: Double = 0; AMaxHeight: Double = 0);
procedure Merge; overload;
procedure Merge(Across: OleVariant); overload;
procedure Unmerge;
function Offset(DRow, DCol: Integer): TXLSXRange;
function Resize(NewRowCount, NewColCount: Integer): TXLSXRange;
procedure Sort(AKeyColumn: Integer; ADescending: Boolean = False); overload;
procedure Sort(const AKeyColumns: array of Integer; const ADescending: array of Boolean); overload;
procedure ApplyBuiltinStyle(AStyle: TXLSXBuiltinCellStyle);
procedure CopyTo(ADestRow, ADestCol: Integer);
procedure MoveTo(ADestRow, ADestCol: Integer);
procedure InsertRows;
procedure DeleteRows;
procedure InsertCols;
procedure DeleteCols;
procedure ApplyFormatPatch(ASource: TXLSXRange; AParts: TXLSXFormatParts);
function CopyToClipboard: Boolean;
function SaveAsPDF(const FileName: WideString): Integer; overload;
function SaveAsPDF(Stream: TStream): Integer; overload;
function SetDynamicArrayFormula(const F: WideString): Integer;
end;
Members
| Member |
Description |
| Create(ASheet, ARow1, ACol1, ARow2, ACol2) |
Builds a new worksheet-owned range and normalizes
reversed corners so Row1/Col1 are always
the upper-left coordinate |
| RefA1 |
以 A1 文本返回范围引用。单单元格范围返回单个单元格引用,例如 B2 |
| SaveAsHTML |
Options overloads accept TXLSXHtmlExportOptions for Title, WriteDocument, IncludeStyles, IncludeBOM, and TableClass. Set WriteDocument to False for a table fragment; set IncludeBOM to False (把输出内嵌到既有 UTF-8 响应时)。同样的选项也适用于选定范围的 HTML 导出。导出输出把单元格超链接保留为 <a> anchors and anchored images as inline data: 图片 URI(当它们落在所选矩形内时)。所选矩形内的单元格批注也会以转义后的 <td> title attributes. When IncludeStyles is enabled, explicit ColWidth values are emitted as <col> widths and explicit RowHeight values as <tr> height styles. Rich-text cell runs are emitted as escaped <span> elements with inline font, color, emphasis, and underline styles when IncludeStyles is enabled. Cell borders are emitted as CSS border-left, border-right, border-top, and border-bottom rules when IncludeStyles is enabled. Hidden rows and columns marked by RowHidden / ColHidden, plus explicit zero-width columns, are skipped in the generated table and <colgroup>. Vertical alignment settings are emitted as CSS vertical-align rules when IncludeStyles is enabled |
| SetValue / SetFormula |
通过工作表单元格集合,把同一个值或公式文本写入范围内的每个单元格 |
| SetArrayFormula |
设置 a multi-cell CSE array formula over the range. The top-left cell stores the formula text and anchors the spill range, while the remaining cells point back to that root so each cell evaluates its own element of the matrix result. Pass formula text without the surrounding braces |
| ClearValues / Clear / ClearAll |
ClearValues and Clear remove values and formulas while preserving style indexes. ClearAll also clears style indexes |
| SetFontIndex / SetFillIndex / SetBorderIndex / SetNumberFormatIndex / SetAlignmentIndex |
把从 1 开始的工作簿调色板索引应用到范围内的每个单元格。传 0 会清除对应的单元格级索引 |
| SetNumberFormat |
在工作簿调色板中查找或追加数字格式字符串,然后把得到的从 1 开始的索引应用到范围。空格式会清除单元格级索引 |
| SetBorders |
Composes border edges over the range. TXLSXBorderEdgeKind accepts xlsxEdgeAll, xlsxEdgeOutline, xlsxEdgeInside, xlsxEdgeInsideHorizontal, xlsxEdgeInsideVertical, xlsxEdgeTop, xlsxEdgeBottom, xlsxEdgeLeft, xlsxEdgeRight, xlsxEdgeDiagonalUp, and xlsxEdgeDiagonalDown。使用外框和内部边选择器构建表格边框,不会替换无关的边设置 |
| SetLocked / SetFormulaHidden |
通过复用工作簿保护样式池,把单元格保护标志应用到范围内的每个单元格 |
| AutoFitColumns / AutoFitRows |
转发到工作表的自动适配辅助方法,作用于范围的列或行边界。可选的宽度和高度限制会透传,让报表布局保持在设计边界内 |
| Merge / Unmerge |
Merge and Merge(False) create one merged rectangle. Merge(True) creates one merged range per row, matching Excel's merge-across behavior. Unmerge removes an exact merged-range match |
| Offset / Resize |
返回另一个由工作表持有的范围:从当前边界偏移,或调整为请求的行数和列数 |
| Sort |
按单个键列或按优先级排列的多个键列,对该范围内的行进行排序。 ADescending
为每个键选择升序或降序;省略的条目默认为升序。空值排在最后 |
| ApplyBuiltinStyle |
把 Excel 内置单元格样式的可见外观应用到范围内的每个单元格。该辅助方法写出直接格式:把匹配的字体和填充加入工作簿池,并把得到的索引赋给单元格 |
| CopyTo / MoveTo |
把整个范围复制或移动到目标左上角单元格。值、公式、富文本负载、样式索引、批注、超链接和绘图锚点都经由工作表的范围复制与范围移动辅助方法转发 |
| InsertRows / DeleteRows / InsertCols / DeleteCols |
对范围边界执行整行或整列的插入与删除。这些辅助方法转发到工作表的行/列移位操作,使公式、引用、筛选、页面设置范围、图表范围、名称、图片和图表锚点与编辑后的网格保持对齐 |
| ApplyFormatPatch |
使用 TXLSXFormatParts 标志,把另一个源范围的选择性格式样式应用到本范围 |
| CopyToClipboard |
Copies the range values and styles to the Windows clipboard |
| SaveAsPDF |
使用进程内 PDF 渲染引擎把单元格范围导出为 PDF 文件或流 |
| SetDynamicArrayFormula |
设置 a dynamic array formula over the range, supporting Excel's dynamic spill behavior |
Ownership and bounds
范围由创建它的工作表所有,并随该工作表一起释放。应用程序代码不应调用 Free on a TXLSXRange
,也不要在工作表或工作簿销毁后继续持有范围引用
数字坐标从 1 开始。创建范围时会规范化颠倒的角点,并把边界钳制在 XLSX 工作表上限内
示例
var
Wb: TXLSXWorkbook;
Ws: TXLSXWorksheet;
Body: TXLSXRange;
begin
Wb := TXLSXWorkbook.Create;
try
Ws := Wb.Sheets.Add('Report');
Body := Ws.Range['B2:D20'];
Body.SetNumberFormat('#,##0.00');
Body.SetBorders(xlsxEdgeOutline, xlsxBorderThin, $FF808080);
Body.Sort(2);
Body.ApplyBuiltinStyle(xbsAccent1);
Ws.Range['F2:G3'].SetArrayFormula('MMULT(A2:B3,D2:E3)');
Body.AutoFitColumns;
Body.SaveAsHTML('report-fragment.html');
finally
Wb.Free;
end;
end;
请参阅