เอกสาร HotXLS

TXLSXWorksheet class

Single worksheet inside a TXLSXWorkbook Owns the cell collection plus the merged-cell, hyperlink, and comment collections. Declared in lxHandleX

Declaration

type
  TXLSXTextBox = class
    constructor Create(const AText: WideString; AFromRow, AFromCol, AToRow, AToCol: Integer);
    property Text: WideString;
    property FromRow, FromCol, ToRow, ToCol: Integer;
  end;

  TXLSXWorksheet = class
    constructor Create(const AName: WideString);
    destructor Destroy; override;
    procedure SetWorkbook(AWorkbook: TXLSXWorkbook);
    function MergeCells(ARow1, ACol1, ARow2, ACol2: Integer): Integer;
    function AddHyperlink(ARow, ACol: Integer; const AUrl: WideString): Integer; overload;
    function AddHyperlink(ARow, ACol: Integer; const AUrl, ADisplay: WideString): Integer; overload;
    function AddHyperlink(ARow, ACol: Integer; const AUrl, ADisplay, ATooltip: WideString): Integer; overload;
    function AddComment(ARow, ACol: Integer; const AText: WideString): Integer; overload;
    function AddComment(ARow, ACol: Integer; const AText, AAuthor: WideString): Integer; overload;
    function AddImage(ARow, ACol: Integer; const AData: AnsiString; AFormat: TXLSXImageFormat): Integer;
    function AddImageFromFile(ARow, ACol: Integer; const AFileName: WideString): Integer;
    function AddConditionalFormat(const ARange: WideString; AOp: TXLSXCfOperator; const AFormula1: WideString): Integer; overload;
    function AddConditionalFormat(const ARange: WideString; AOp: TXLSXCfOperator; const AFormula1, AFormula2: WideString): Integer; overload;
    // Excel 2007+ extension rules (v2.36.0+) — mirror the BIFF8 TXLSWorksheet API.
    function AddCondFormatDataBar(const ARange: WideString; AColor: LongWord;
      AMinKind: TXLSCfValueKind = cfvMinOfRange; const AMinValue: WideString = '';
      AMaxKind: TXLSCfValueKind = cfvMaxOfRange; const AMaxValue: WideString = ''): Integer;
    function AddCondFormatColorScale2(const ARange: WideString;
      AMinColor, AMaxColor: LongWord;
      AMinKind: TXLSCfValueKind = cfvMinOfRange; const AMinValue: WideString = '';
      AMaxKind: TXLSCfValueKind = cfvMaxOfRange; const AMaxValue: WideString = ''): Integer;
    function AddCondFormatColorScale3(const ARange: WideString;
      AMinColor, AMidColor, AMaxColor: LongWord;
      AMinKind: TXLSCfValueKind = cfvMinOfRange; const AMinValue: WideString = '';
      AMidKind: TXLSCfValueKind = cfvPercentile; const AMidValue: WideString = '50';
      AMaxKind: TXLSCfValueKind = cfvMaxOfRange; const AMaxValue: WideString = ''): Integer;
    function AddCondFormatIconSet(const ARange: WideString;
      ASetType: TXLSIconSetType): Integer;
    function AddCondFormatExpression(const ARange: WideString;
      const AFormula: WideString): Integer;
    function AddCondFormatContainsText(const ARange, AText: WideString): Integer;
    function AddCondFormatNotContainsText(const ARange, AText: WideString): Integer;
    function AddCondFormatBeginsWith(const ARange, AText: WideString): Integer;
    function AddCondFormatEndsWith(const ARange, AText: WideString): Integer;
    function AddCondFormatTop10(const ARange: WideString; ARank: Integer;
      ABottom: Boolean = False; APercent: Boolean = False): Integer;
    function AddCondFormatAboveAverage(const ARange: WideString;
      AAbove: Boolean = True): Integer;
    function AddCondFormatDuplicateValues(const ARange: WideString): Integer;
    function AddCondFormatUniqueValues(const ARange: WideString): Integer;
    function AddCondFormatContainsBlanks(const ARange: WideString): Integer;
    function AddCondFormatNotContainsBlanks(const ARange: WideString): Integer;
    function AddCondFormatContainsErrors(const ARange: WideString): Integer;
    function AddCondFormatNotContainsErrors(const ARange: WideString): Integer;
    function AddDataValidation(const ARange: WideString; AType: TXLSXDataValidationType; AOp: TXLSXDvOperator; const AFormula1: WideString): Integer; overload;
    function AddDataValidation(const ARange: WideString; AType: TXLSXDataValidationType; AOp: TXLSXDvOperator; const AFormula1, AFormula2: WideString): Integer; overload;
    function AddListValidation(const ARange, AItems: WideString): Integer;
    function AddWholeNumberValidation(const ARange: WideString; AOp: TXLSXDvOperator; const AFormula1: WideString): Integer; overload;
    function AddWholeNumberValidation(const ARange: WideString; AOp: TXLSXDvOperator; const AFormula1, AFormula2: WideString): Integer; overload;
    function AddDecimalValidation(const ARange: WideString; AOp: TXLSXDvOperator; const AFormula1: WideString): Integer; overload;
    function AddDecimalValidation(const ARange: WideString; AOp: TXLSXDvOperator; const AFormula1, AFormula2: WideString): Integer; overload;
    function AddDateValidation(const ARange: WideString; AOp: TXLSXDvOperator; const AFormula1: WideString): Integer; overload;
    function AddDateValidation(const ARange: WideString; AOp: TXLSXDvOperator; const AFormula1, AFormula2: WideString): Integer; overload;
    function AddTimeValidation(const ARange: WideString; AOp: TXLSXDvOperator; const AFormula1: WideString): Integer; overload;
    function AddTimeValidation(const ARange: WideString; AOp: TXLSXDvOperator; const AFormula1, AFormula2: WideString): Integer; overload;
    function AddTextLengthValidation(const ARange: WideString; AOp: TXLSXDvOperator; const AFormula1: WideString): Integer; overload;
    function AddTextLengthValidation(const ARange: WideString; AOp: TXLSXDvOperator; const AFormula1, AFormula2: WideString): Integer; overload;
    function AddCustomValidation(const ARange, AFormula: WideString): Integer;
    // Excel-style table (insert table) — see TXLSXTable.
    function AddTable(const AName, ARange: WideString; AColumns: TStrings): Integer;
    // Chart helpers — anchored or full-page (via AddChartSheet on workbook).
    function AddChart(AChartType: TXLSXChartType; const ATitle: WideString;
      AFromRow, AFromCol, AToRow, AToCol: Integer): TXLSXChart;
    // Standalone drawing text boxes.
    function AddTextBox(const AText: WideString;
      AFromRow, AFromCol, AToRow, AToCol: Integer): TXLSXTextBox;
    function TextBoxCount: Integer;
    function TextBox(Index: Integer): TXLSXTextBox;
    function IndexOfTextBoxAt(ARow, ACol: Integer): Integer;
    function FindTextBoxAt(ARow, ACol: Integer): TXLSXTextBox;
    procedure DeleteTextBox(Index: Integer);
    function DeleteTextBoxAt(ARow, ACol: Integer): Boolean;
    function DeleteTextBoxesInRange(ARow1, ACol1, ARow2, ACol2: Integer): Integer;
    procedure ClearTextBoxes;
    // Internal Sheet!Cell hyperlink (no rels relationship needed).
    function AddHyperlinkToCell(ARow, ACol: Integer; const ALocation: WideString): Integer; overload;
    function AddHyperlinkToCell(ARow, ACol: Integer; const ALocation, ADisplay: WideString): Integer; overload;
    function AddHyperlinkToCell(ARow, ACol: Integer; const ALocation, ADisplay, ATooltip: WideString): Integer; overload;
    // Sheet visibility and selection state.
    property Visibility: TXLSXSheetVisibility;
    property Visible: Boolean;
    property IsSelected: Boolean;
    procedure SetIsSelected(Value: Boolean);
    // Auto-fit column width / row height from cell content.
    procedure AutoFitColumn(ACol: Integer; AMinWidth: Double = 0; AMaxWidth: Double = 0);
    procedure AutoFitColumns(AColMin, AColMax: Integer; AMinWidth: Double = 0; AMaxWidth: Double = 0);
    procedure AutoFitRow(ARow: Integer; AMinHeight: Double = 0; AMaxHeight: Double = 0);
    procedure AutoFitRows(ARowMin, ARowMax: Integer; AMinHeight: Double = 0; AMaxHeight: Double = 0);
    // Row / column insert and delete with cascade shift.
    procedure InsertRows(BeforeRow, Count: Integer);
    procedure DeleteRows(StartRow, Count: Integer);
    procedure InsertCols(BeforeCol, Count: Integer);
    procedure DeleteCols(StartCol, Count: Integer);
    // Manual page breaks.
    procedure AddRowBreak(BeforeRow: Integer);
    procedure AddColBreak(BeforeCol: Integer);
    function  HasRowBreak(BeforeRow: Integer): Boolean;
    function  HasColBreak(BeforeCol: Integer): Boolean;
    function  IndexOfRowBreak(BeforeRow: Integer): Integer;
    function  IndexOfColBreak(BeforeCol: Integer): Integer;
    procedure RemoveRowBreak(BeforeRow: Integer);
    procedure RemoveColBreak(BeforeCol: Integer);
    function  RemoveRowBreaksInRange(FirstRow, LastRow: Integer): Integer;
    function  RemoveColBreaksInRange(FirstCol, LastCol: Integer): Integer;
    procedure ClearRowBreaks;
    procedure ClearColBreaks;
    procedure ClearAllPageBreaks;
    function  RowBreakCount: Integer;
    function  ColBreakCount: Integer;
    function  RowBreaks(Index: Integer): Integer;
    function  ColBreaks(Index: Integer): Integer;
    function Calculate(const Formula: WideString): Variant;
    function ForEachCell(Callback: TXLSXCellReadEvent): Integer;
    function ForEachRow(Callback: TXLSXRowReadEvent): Integer;
    function FindText(const SearchText: WideString; out Row, Col: Integer): Boolean; overload;
    function FindText(const SearchText: WideString; out Row, Col: Integer; MatchCase: Boolean): Boolean; overload;
    function ReplaceText(const SearchText, ReplacementText: WideString): Integer; overload;
    function ReplaceText(const SearchText, ReplacementText: WideString; MatchCase: Boolean): Integer; overload;
    function WriteCells(const ARange: WideString; Callback: TXLSXCellWriteEvent): Integer; overload;
    function WriteCells(ARow1, ACol1, ARow2, ACol2: Integer; Callback: TXLSXCellWriteEvent): Integer; overload;
    function WriteRows(const ARange: WideString; Callback: TXLSXRowWriteEvent): Integer; overload;
    function WriteRows(ARow1, ACol1, ARow2, ACol2: Integer; Callback: TXLSXRowWriteEvent): Integer; overload;
    // Column / row metadata.
    procedure SetColWidth(ACol: Integer; AWidth: Double);
    function HasColWidth(ACol: Integer): Boolean;
    procedure ClearColWidths;
    procedure SetRowHeight(ARow: Integer; AHeight: Double);
    function HasRowHeight(ARow: Integer): Boolean;
    procedure ClearRowHeights;
    procedure SetRowOutlineLevel(ARow, ALevel: Integer);
    function HasRowOutlineLevel(ARow: Integer): Boolean;
    procedure ClearRowOutlineLevels;
    procedure SetColOutlineLevel(ACol, ALevel: Integer);
    function HasColOutlineLevel(ACol: Integer): Boolean;
    procedure ClearColOutlineLevels;
    procedure SetRowHidden(ARow: Integer; AHidden: Boolean);
    procedure SetColHidden(ACol: Integer; AHidden: Boolean);
    procedure ClearRowHidden;
    procedure ClearColHidden;
    procedure SetRowCollapsed(ARow: Integer; ACollapsed: Boolean);
    procedure SetColCollapsed(ACol: Integer; ACollapsed: Boolean);
    procedure ClearRowCollapsed;
    procedure ClearColCollapsed;
    // Range copy / move / clear API.
    procedure ClearRangeValues(const ARange: WideString); overload;
    procedure ClearRangeValues(ARow1, ACol1, ARow2, ACol2: Integer); overload;
    procedure ClearRange(ARow1, ACol1, ARow2, ACol2: Integer);
    procedure CopyRange(ASrcRow1, ASrcCol1, ASrcRow2, ASrcCol2, ADstRow, ADstCol: Integer);
    procedure CopyRangeTo(ASrcRow1, ASrcCol1, ASrcRow2, ASrcCol2: Integer;
      ATargetSheet: TXLSXWorksheet; ADstRow, ADstCol: Integer);
    procedure CopyFrom(ASource: TXLSXWorksheet);
    procedure MoveRange(ASrcRow1, ASrcCol1, ASrcRow2, ASrcCol2, ADstRow, ADstCol: Integer);
    procedure SortRange(ARow1, ACol1, ARow2, ACol2: Integer;
      const AKeyCols: array of Integer; const ADescending: array of Boolean);
    // Frozen panes (top rows / left columns).
    procedure FreezePanes(ARow, ACol: Integer);
    procedure UnfreezePane;
    property FreezeCol, FreezeRow: Integer;
    // Page setup.
    procedure SetPageMargins(ALeft, ARight, ATop, ABottom: Double); overload;
    procedure SetPageMargins(ALeft, ARight, ATop, ABottom, AHeader, AFooter: Double); overload;
    property MarginLeft, MarginRight, MarginTop, MarginBottom,
             MarginHeader, MarginFooter: Double;
    property MarginLeftCM, MarginRightCM, MarginTopCM, MarginBottomCM,
             MarginHeaderCM, MarginFooterCM: Double;
    property PageLandscape: Boolean;
    property PaperSize, PageScale, FitToWidth, FitToHeight: Integer;
    property HeaderText, FooterText: WideString;
    property LeftHeader, CenterHeader, RightHeader: WideString;
    property LeftFooter, CenterFooter, RightFooter: WideString;
    property CenterHorizontally, CenterVertically: Boolean;
    property PrintGridlines: Boolean;
    property PrintHeadings: Boolean;
    property BlackAndWhite: Boolean;
    property Draft: Boolean;
    property PrintNotes: Boolean;
    property PrintOverThenDown: Boolean;
    property PrintArea: WideString;
    property PrintTitleRows: WideString;
    property PrintTitleCols: WideString;
    // Auto-filter range (e.g. "A1:C100"). Empty = no filter.
    procedure SetAutoFilter(ARow1, ACol1, ARow2, ACol2: Integer); overload;
    procedure SetAutoFilter(const ARange: WideString); overload;
    procedure ClearAutoFilter;
    property AutoFilterRange: WideString;
    property AutoFilterColumns: TXLSXAutoFilterColumns;
    function AddAutoFilterColumn(AColId: Integer; AOp1: TXLSXAutoFilterOp; const ACriteria1: WideString): TXLSXAutoFilterColumn; overload;
    function AddAutoFilterColumn(AColId: Integer; AOp1: TXLSXAutoFilterOp; const ACriteria1: WideString; AOp2: TXLSXAutoFilterOp; const ACriteria2: WideString; AAndConnector: Boolean): TXLSXAutoFilterColumn; overload;
    procedure ClearAutoFilterColumns;
    function AutoFilterRowVisible(ARow: Integer): Boolean;
    function PreviewAutoFilterRows(Callback: TXLSXAutoFilterRowEvent): Integer;
    function ApplyAutoFilter(const ARange: WideString): Boolean;
    // Sheet protection (16-bit legacy hash).
    procedure Protect; overload;
    procedure Protect(const APassword: WideString); overload;
    procedure UnProtect;
    property IsProtected: Boolean;
    property AllowOption[Option: TXLSXSheetProtectionOption]: Boolean;
    property SheetProtectionOptions: TXLSXSheetProtectionOptions;
    property PageSetupTouched: Boolean;
    property SheetProtectHash: WideString;
    // Sheet tab color + chart-sheet flag.
    property TabColor: LongWord;
    property TabColorIsAuto: Boolean;
    property IsChartSheet: Boolean;
    property Name: WideString;
    property Workbook: TXLSXWorkbook;
    property AlignWithMargins: Boolean;
    property CodeName: WideString;
    property ConsolidateXml: WideString;
    property DifferentFirst: Boolean;
    property DifferentOddEven: Boolean;
    property EvenFooterText: WideString;
    property EvenHeaderText: WideString;
    property FirstFooterText: WideString;
    property FirstHeaderText: WideString;
    property FirstPageNumber: Integer;
    property GridColor: LongWord;
    property HorizontalDpi: Integer;
    property OutlineLevelCol: Integer;
    property OutlineLevelRow: Integer;
    property PaneState: WideString;
    property PhoneticAlignment: WideString;
    property PhoneticFontId: Integer;
    property PhoneticType: WideString;
    property PrintErrors: Integer;
    property ScaleWithDoc: Boolean;
    property ScenariosXml: WideString;
    property SheetProtectAlgorithmName: WideString;
    property SheetProtectHashValue: WideString;
    property SheetProtectSaltValue: WideString;
    property SheetProtectSpinCount: Integer;
    property ShowFormulas: Boolean;
    property ShowOutlineSymbols: Boolean;
    property SortState: TXLSXSortState;
    property SortStateXml: WideString;
    property SummaryBelow: Boolean;
    property SummaryRight: Boolean;
    property UseFirstPageNumber: Boolean;
    property UsePrinterDefaults: Boolean;
    property VerticalDpi: Integer;
    property ZeroHeight: Boolean;
    property ZoomNormal: Integer;
    property ZoomPageLayout: Integer;
    property ZoomSheetLayout: Integer;
    // Sheet view display options.
    property View: TXLSXWindowView;
    property Zoom: Integer;
    property DisplayGridLines: Boolean;
    property DisplayZeros: Boolean;
    property DisplayRightToLeft: Boolean;
    property StandardWidth: Double;
    property StandardHeight: Double;
    // Collections owned by the worksheet.
    property Cells: TXLSXCells;
    property MergedCells: TXLSXMergedCells;
    property Hyperlinks: TXLSXHyperlinks;
    property Comments: TXLSXComments;
    property Images: TXLSXImages;
    property ConditionalFormats: TXLSXConditionalFormats;
    property DataValidations: TXLSXDataValidations;
    property Tables: TXLSXTables;
    property Charts: TXLSXCharts;
    property PivotTables: TXLSPivotTables;
    function AddPivotTable(const AName, ARange, ADestRange: WideString): TXLSPivotTable;
    function AddPivotTableCopy(ASrcPivot: TXLSPivotTable; const ADestRange: WideString): TXLSPivotTable;
    procedure PivotSetDataFieldFormat(APivotField: TXLSPivotDataField; const AFormat: WideString);
    property ColWidth[ACol: Integer]: Double;
    property RowHeight[ARow: Integer]: Double;
    property RowOutlineLevel[ARow: Integer]: Integer;
    property ColOutlineLevel[ACol: Integer]: Integer;
    property RowHidden[ARow: Integer]: Boolean;
    property ColHidden[ACol: Integer]: Boolean;
    property RowCollapsed[ARow: Integer]: Boolean;
    property ColCollapsed[ACol: Integer]: Boolean;
    property Range[const Ref: WideString]: TXLSXRange;
    property RCRange[R1, C1, R2, C2: Integer]: TXLSXRange;
    property UsedRange: TXLSXRange;
    function EntireRow(ARow: Integer): TXLSXRange;
    function EntireColumn(ACol: Integer): TXLSXRange;
    property ProtectedRanges: TXLSXProtectedRanges;
    property RawWorksheetExts: TXLSXRawWorksheetExts;
    property SparklineGroups: TXLSXSparklineGroups;
    property ThreadedComments: TXLSXThreadedComments;
    function AddAreaChart(AChartType: TXLSXChartType; const ATitle: WideString; AFromRow, AFromCol, AToRow, AToCol: Integer): TXLSXChart;
    function AddBarChart(AChartType: TXLSXChartType; const ATitle: WideString; AFromRow, AFromCol, AToRow, AToCol: Integer): TXLSXChart;
    function AddChartFromRange(const ARange: WideString; AChartType: TXLSXChartType): TXLSXChart;
    function AddColumnChart(AChartType: TXLSXChartType; const ATitle: WideString; AFromRow, AFromCol, AToRow, AToCol: Integer): TXLSXChart;
    function AddLineChart(AChartType: TXLSXChartType; const ATitle: WideString; AFromRow, AFromCol, AToRow, AToCol: Integer): TXLSXChart;
    function AddPieChart(AChartType: TXLSXChartType; const ATitle: WideString; AFromRow, AFromCol, AToRow, AToCol: Integer): TXLSXChart;
    function AddSparklineGroup(const ARange, ALocation: WideString; AType: TXLSXSparklineType): TXLSXSparklineGroup;
    function AddThreadedComment(ARow, ACol: Integer; const AText, AAuthor: WideString): TXLSXThreadedComment;
    function AddThreadedReply(AParentComment: TXLSXThreadedComment; const AText, AAuthor: WideString): TXLSXThreadedComment;
    function GetSheetProtectOption(Option: TXLSXSheetProtectionOption): Boolean;
    procedure SetSheetProtectOption(Option: TXLSXSheetProtectionOption; Value: Boolean);
    procedure PasteFromClipboard(StartRow, StartCol: Integer);
    function AddWordArt(const AText, APreset: WideString; AFromRow, AFromCol, AToRow, AToCol: Integer): TXLSXTextBox;
    procedure BuildRowMajorCellOrder;
    procedure ClearRawDrawingAnchors;
    function CreateConditionalFormatEvaluator: TXLSXConditionalFormatEvaluator;
    function RawDrawingAnchor(Index: Integer): WideString;
    function RawDrawingAnchorCount: Integer;
    function SaveAsPDF(const FileName: WideString): Integer; overload;
    function SaveAsPDF(Stream: TStream): Integer; overload;
    procedure ToggleColGrouped(ACol: Integer; AGrouped: Boolean);
    procedure ToggleRowGrouped(ARow: Integer; AGrouped: Boolean);
  end;

  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
    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;
    procedure SetValue(const V: Variant);
    procedure SetFormula(const F: WideString);
    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;
  end;
      

Members

Name Worksheet tab name as shown by Excel
SetWorkbook / Workbook Sets and exposes the workbook back-reference used by cell and workbook-shared helpers such as shared number formats, fills, borders, and shared-string lookups
Cells Cell collection. Use Cells.Item[Row, Col].Value See TXLSXCells / TXLSXCell
Calculate Compiles and evaluates an Excel formula string in this worksheet context A leading = is accepted, and worksheet-local references, referenced formula cells, cross-sheet references, defined-name ranges, and supported text, date, workday, engineering/base-conversion, bitwise, statistical, aggregate, and math functions are resolved by the workbook shared formula evaluator
ForEachCell / ForEachRow / FindText / ReplaceText / WriteCells / WriteRows Helpers for loaded-cell and loaded-row scanning, text search, text replacement, and range filling. ForEachCell walks existing cells in row order with value and formula text. ForEachRow walks existing rows in row order and reports each row's first and last loaded columns. FindText and ReplaceText scan loaded text cells in row order, skip formulas and non-text values, and can match case sensitively. WriteCells requests values for a numeric or A1-style range and supports per-cell skip and cancellation. WriteRows requests a Variant array for each row and supports whole-row skip and cancellation
MergedCells Merged-range collection. See TXLSXMergedCells
Hyperlinks Hyperlink collection. See TXLSXHyperlinks
Comments Cell-comment collection. See TXLSXComments
Tables / AddTable Excel-style table band on the worksheet. See TXLSXTable / TXLSXTables
Charts / AddChart Anchored chart collection. See TXLSXChart / TXLSXCharts The chart type enum supports column, bar, line, pie, area, doughnut, scatter, bubble, and radar charts For a full-page chart, use Workbook.AddChartSheet(...)
AddTextBox / TextBoxCount / TextBox / FindTextBoxAt Creates, enumerates, locates, deletes, and clears standalone drawing text boxes anchored to cell rectangles IndexOfTextBoxAt and FindTextBoxAt locate the first text box containing a cell, while DeleteTextBoxAt, DeleteTextBoxesInRange, DeleteTextBox, and ClearTextBoxes remove individual or grouped text boxes without touching cell comments
AddHyperlinkToCell overloads Internal anchor hyperlink — jumps to a Sheet!Cell location elsewhere in the workbook. No rels relationship is generated. See TXLSXHyperlink.Location
RowOutlineLevel / ColOutlineLevel Group nesting level (0..7) for the matching row or column. SaveAs emits outlineLevel="N" on the row / col entry
RowHidden / ColHidden Boolean — drops the row or column from view (hidden="1")
RowCollapsed / ColCollapsed Boolean — marks a row / column whose grouping parent is collapsed (collapsed="1")
FreezePanes(Row, Col) / UnfreezePane Sets a frozen split — the top Row rows and left Col columns stay visible while the remainder scrolls. FreezeCol and FreezeRow are read-only properties exposing the current split
SetPageMargins / Page setup properties All six margins plus PageLandscape, PaperSize, PageScale, FitToWidth, FitToHeight, HeaderText, FooterText, LeftHeader, CenterHeader, RightHeader, LeftFooter, CenterFooter, RightFooter, CenterHorizontally, and CenterVertically. Setting any one triggers the corresponding <pageMargins>, <pageSetup>, and <headerFooter> blocks on SaveAs. Use the named xlsxPaper* constants such as xlsxPaperLetter, xlsxPaperA4, xlsxPaperA3, and xlsxPaperLegal instead of raw Excel paper-size codes when possible
Visibility Sheet visibility: xlsxSheetVisible (default), xlsxSheetHidden (hidden but unhideable in Excel UI), or xlsxSheetVeryHidden (requires VBA or code to unhide). SaveAs emits a state attribute on the <sheet> element in xl/workbook.xml Visible is a Boolean convenience alias for common show or hide operations
SetIsSelected / IsSelected When True, the sheet tab appears selected (highlighted). Multiple sheets may be selected simultaneously. SaveAs emits tabSelected="1" on the matching <sheetView>
AutoFitColumn / AutoFitColumns AutoFitColumn(Col, MinWidth, MaxWidth) measures every cell in the column and sets ColWidth[Col] to the widest content (ASCII = 1 ch, CJK = 2 ch, Calibri 11pt scale), then applies optional minimum and maximum width limits AutoFitColumns(Min, Max, MinWidth, MaxWidth) iterates the column range, clamped to the last cell-bearing column
AutoFitRow / AutoFitRows AutoFitRow(Row, MinHeight, MaxHeight) sets RowHeight[Row] to the tallest cell content in that row (in points), then applies optional minimum and maximum height limits AutoFitRows(Min, Max, MinHeight, MaxHeight) iterates the row range, clamped to the last cell-bearing row
InsertRows / DeleteRows InsertRows(BeforeRow, Count) shifts every row at BeforeRow or below down by Count. DeleteRows(StartRow, Count) removes rows [StartRow, StartRow+Count-1] and pulls the remainder up. Both cascade through cells, merged ranges, row heights, outline levels, hidden flags, hyperlinks, comments, freeze pane, and auto-filter / conditional-format / data-validation references, tables, cell formulas, conditional-format / data-validation formulas, internal hyperlink targets, print setup references, manual page breaks, auto-filter column criteria, chart series ranges, and defined names that point at the edited worksheet, image anchors, and chart anchors
InsertCols / DeleteCols Same as InsertRows / DeleteRows but operating on columns. Column widths, outline levels, and hidden flags are also updated
AddRowBreak / AddColBreak AddRowBreak(N) inserts a manual page break before row N (i.e. row N starts a new printed page). AddColBreak(N) breaks before column N. SaveAs writes <rowBreaks> / <colBreaks> in the sheet XML
HasRowBreak / HasColBreak / IndexOfRowBreak / IndexOfColBreak Query or locate a single manual break by its "before" index
RemoveRowBreak / RemoveColBreak / RemoveRowBreaksInRange / RemoveColBreaksInRange Remove one manual break or all breaks in an inclusive row / column interval; range helpers accept reversed coordinates and return the number of removed breaks
ClearRowBreaks / ClearColBreaks / ClearAllPageBreaks Remove all row breaks, all column breaks, or both
RowBreakCount / ColBreakCount / RowBreaks[i] / ColBreaks[i] Iterate stored break indices (1-based "Before" values)
PrintGridlines / PrintHeadings When True, SaveAs emits printGridLines="1" / printRowColHeadings="1" inside <printOptions> so row/column grid lines or headings appear on the printed page
BlackAndWhite / Draft / PrintNotes / PrintOverThenDown Print options in <pageSetup>: BlackAndWhite renders in B&W; Draft suppresses graphics for faster preview; PrintNotes prints cell comments as displayed; PrintOverThenDown switches page order to left-to-right-first instead of top-to-bottom-first
PrintArea The rectangular region Excel prints (e.g "$A$1:$D$10"). Written as a workbook-level <definedName name="_xlnm.Print_Area"> scoped to this sheet. Empty string = not set
PrintTitleRows / PrintTitleCols Row or column ranges that repeat on every printed page (e.g. "$1:$3" or "$A:$B"). Written as <definedName name="_xlnm.Print_Titles">
SetAutoFilter / AutoFilterRange Sets the filter range (e.g "A1:C100"); SaveAs writes <autoFilter ref="..."/>
AutoFilterColumns / AddAutoFilterColumn / ClearAutoFilterColumns Per-column filter criteria attached to the auto-filter range. AddAutoFilterColumn(ColId, Op, Criteria) adds a single-criterion filter; the two-criteria overload adds an AND/OR pair AutoFilterColumns.FindByColId(ColId) returns an existing criteria object, and AutoFilterColumns.DeleteByColId(ColId) removes one without scanning Items manually, and AutoFilterColumns.ClearCriteria clears all column criteria while preserving the filter range ColId is the 0-based offset within the auto-filter range (not the sheet column). SaveAs writes <filterColumn> children inside <autoFilter>
AutoFilterRowVisible / PreviewAutoFilterRows / ApplyAutoFilter AutoFilterRowVisible(Row) evaluates the stored XLSX AutoFilter criteria for one data row. PreviewAutoFilterRows walks the data rows in AutoFilterRange, reports each row's visible state through a callback, returns the number of visible rows visited, and does not change row hidden flags. ApplyAutoFilter applies the autofilter criteria, hides rows that do not match, and returns whether it succeeded
Protect / UnProtect / IsProtected Sheet-level protection toggle with an optional 16-bit legacy password hash. Reflected as <sheetProtection>
AllowOption / SheetProtectionOptions 15 fine-grained protection permission options (such as formatting cells, inserting rows/columns, sorting, auto-filtering, selecting locked/unlocked cells, etc.), corresponding to Excel's "Protect Sheet" permissions list
PageSetupTouched / SheetProtectHash Use PageSetupTouched to inspect whether page setup values were explicitly modified, and SheetProtectHash to read/write the legacy 16-bit sheet protection hash text used by legacy XLS file formats
AddPivotTable / AddPivotTableCopy / PivotSetDataFieldFormat Methods to create, copy and format pivot tables. AddPivotTable creates a new pivot table from the specified source range and places it at the destination range. AddPivotTableCopy copies an existing pivot table to a new destination range on this worksheet. PivotSetDataFieldFormat sets the display format for a pivot table data field
PivotTables Collection of pivot tables defined on this worksheet
MarginLeftCM / MarginRightCM / MarginTopCM / MarginBottomCM / MarginHeaderCM / MarginFooterCM Page setup margins represented in centimeters
TabColor / TabColorIsAuto ARGB color for the worksheet tab in Excel TabColorIsAuto = True (default) suppresses the <tabColor> child of <sheetPr>
IsChartSheet When True, SaveAs writes the sheet to xl/chartsheets/sheetN.xml instead of xl/worksheets/sheetN.xml and hosts Charts[0] full-page. Use the Workbook.AddChartSheet(...) helper for the typical setup
View Worksheet view mode. Values are xlsxNormalView, xlsxPageBreakPreview, and xlsxPageLayoutView. SaveAs writes the corresponding view attribute on <sheetView>; Open reads it back
Zoom Sheet view zoom percentage (10–400; default 100, clamped on assignment). Emits zoomScale="N" inside <sheetView>; default is suppressed so untouched sheets stay clean
DisplayGridLines When False, hides the cell grid lines in the sheet view. Default True. Emits showGridLines="0" when False
DisplayZeros When False, cells with a zero value render as blank instead of "0". Default True. Emits showZeros="0" when False
DisplayRightToLeft When True, the sheet is displayed in right-to-left layout (column A on the right), suitable for Arabic or Hebrew text. Emits rightToLeft="1"
StandardWidth Default column width in Excel character units (e.g. 8.43 = built-in default). Setting a value > 0 emits <sheetFormatPr defaultColWidth="..."/> 0 = unset (element suppressed)
StandardHeight Default row height in points (e.g. 15 = built-in default). Setting a value > 0 emits defaultRowHeight="..." on <sheetFormatPr> 0 = unset
ClearRangeValues / CopyRange / CopyRangeTo / CopyFrom / MoveRange / SortRange / ClearRange Cell-range operations. CopyRange and CopyRangeTo duplicate values, formulas, style indexes, and rich-text payloads; CopyFrom duplicates the entire worksheet's content and settings (including merged cells, page setup, view state, auto-filters, etc.); MoveRange skips destination overlap; SortRange sorts whole rows inside a rectangle by one or more absolute key columns; ClearRange removes cells; ClearRangeValues clears values and formulas while preserving style indexes
Range / RCRange / UsedRange Return sheet-owned TXLSXRange wrappers for A1 references, 1-based numeric coordinates, or the populated worksheet closure. TXLSXRange.SaveAsHTML(FileName) and TXLSXRange.SaveAsHTML(Stream) export only the selected range as a UTF-8 HTML table. Range wrappers also provide batch values, formulas, style indexes, number formats, borders, protection flags, auto-fit, merge, offset, resize, multi-key sorting, built-in cell styles, copy/move, and whole-row or whole-column insert/delete helpers
EntireRow / EntireColumn Return full-row or full-column ranges for the specified index suitable for structural operations or style propagation
MergeCells(R1, C1, R2, C2) Adds a merged rectangle and returns the new entry index. Coordinates are 1-based, inclusive on both ends. Equivalent to MergedCells.Add(R1, C1, R2, C2). For range-style code, Range['A1:C3'].Merge(True) writes one merged range per row, matching Excel's merge-across command
AddHyperlink overloads Adds an external URL hyperlink to a single cell Display and Tooltip are optional. Equivalent to Hyperlinks.Add(...)
AddComment overloads Adds a comment to a single cell. Author is optional. Equivalent to Comments.Add(...)
ColWidth[Col] Column width in Excel units (same scale used by the Excel column-width dialog). Reading an unset column returns 0; assigning a value sets the width for that 1-based column. SaveAs emits one <col> entry per customized column; Open replays the <cols> block back into the map
RowHeight[Row] Row height in points (same scale used by the Excel row-height dialog). Reading an unset row returns 0; assigning a value sets the height for that 1-based row. SaveAs writes the ht and customHeight="1" attributes on each <row> with a custom height, even rows that carry only a height with no cell data
SetColWidth / SetRowHeight Direct setters used by the indexed properties above Provided as named methods for callers that prefer not to use the property syntax
HasColWidth / HasRowHeight ส่งกลับ True when the worksheet has a customized width or height for the given index. Use this to distinguish "unset" from a deliberate 0 value
ClearColWidths / ClearRowHeights Drops every customized width or height back to the Excel default
ClearRowHidden / ClearColHidden / ClearRowCollapsed / ClearColCollapsed Drops every row or column hidden/collapsed override back to the default visible and expanded state
Images Image collection. Use AddImage / AddImageFromFile as the convenience entry points. See TXLSXImage / TXLSXImages
ConditionalFormats Conditional formatting rules for this worksheet Use AddConditionalFormat as the convenience entry See TXLSXConditionalFormat / TXLSXConditionalFormats
DataValidations Data-validation rules for this worksheet. Use AddDataValidation / AddListValidation as the convenience entries. See TXLSXDataValidation / TXLSXDataValidations
AddImage / AddImageFromFile Adds an image anchored to a cell. AddImage takes the raw bytes plus a TXLSXImageFormat; AddImageFromFile reads the file and infers the format from its extension. Equivalent to Images.Add on the collection
AddConditionalFormat overloads Adds a cellIs conditional-formatting rule Equivalent to ConditionalFormats.Add(...)
AddCondFormatExpression / text / rank / average / duplicate / blank / error helpers Adds specialized conditional-formatting rules for formulas, text matching, top/bottom ranks, above/below-average values, duplicate or unique values, blanks, non-blanks, errors, and non-errors. The returned index can be used with ConditionalFormats[Index].Style to attach formatting
AddWholeNumberValidation / AddWholeNumberValidation overloads / Whole whole-number validations Adds entire wholesale whole number validations with range or criteria support
ProtectedRanges Collection of protected cell ranges requiring password authentication in the sheet.
RawWorksheetExts Exposes raw worksheet extension list data for direct XML injection.
SparklineGroups / AddSparklineGroup Manage inline mini sparkline charts within cells. AddSparklineGroup creates a group referencing a data range.
ThreadedComments / AddThreadedComment / AddThreadedReply Support modern threaded comment conversations (replies). AddThreadedComment creates a top-level threaded comment conversation, and AddThreadedReply appends a reply.
AddAreaChart / AddBarChart / AddChartFromRange / AddColumnChart / AddLineChart / AddPieChart Excel charting shortcuts. AddChartFromRange creates an anchored chart directly from cell data.
GetSheetProtectOption / SetSheetProtectOption Get or set specific sheet protection permission flags programmatically.
PasteFromClipboard Pastes contents from the clipboard directly starting at the specified coordinates
AlignWithMargins ระบุ whether page margins align with worksheet contents
CodeName ระบุ the VBA sheet code name
ConsolidateXml Exposes raw consolidated XML data
DifferentFirst Enables separate first-page header/footer
DifferentOddEven Enables separate odd/even page headers/footers
EvenFooterText / EvenHeaderText Text strings for even-page headers and footers
FirstFooterText / FirstHeaderText Text strings for first-page headers and footers
FirstPageNumber First page print number
GridColor Sheet gridline color
HorizontalDpi / VerticalDpi Print DPI resolutions for horizontal and vertical axes
OutlineLevelCol / OutlineLevelRow Default outline level for columns and rows
PaneState Pane frozen scroll state
PhoneticAlignment / PhoneticFontId / PhoneticType CJK phonetic ruby text alignment, font index, and phonetic type
PrintErrors Cell error printing behavior
ScaleWithDoc Scales headers/footers with document scale
ScenariosXml What-If scenario XML contents
SheetProtectAlgorithmName / SheetProtectHashValue / SheetProtectSaltValue / SheetProtectSpinCount Cryptographic properties for modern sheet-protection password hashes
ShowFormulas Shows formulas instead of values
ShowOutlineSymbols Shows outline group symbols
SortState / SortStateXml Typed sorting criteria and verbatim sort XML contents
SummaryBelow / SummaryRight Outlines summary row and column position
UseFirstPageNumber Uses explicit page numbering start
UsePrinterDefaults Uses printer-default DEVMODE settings
ZeroHeight Hides newly inserted rows by default
ZoomNormal / ZoomPageLayout / ZoomSheetLayout Zoom level values for normal, page layout, and page break views
AddWordArt Adds a WordArt text shape control to the worksheet
BuildRowMajorCellOrder Optimizes cell storage sequentially for row-major iteration
ClearRawDrawingAnchors Clears all raw unmapped drawing shape XML anchors
CreateConditionalFormatEvaluator Instantiates a conditional formatting evaluation utility engine
RawDrawingAnchor / RawDrawingAnchorCount Manages raw unmapped drawing shape XML anchors
SaveAsPDF Exports the worksheet to a PDF file or stream
ToggleColGrouped / ToggleRowGrouped Toggles column or row grouping collapsed state

ตัวอย่าง

var
  ws: TXLSXWorksheet;
begin
  ws := Workbook.Sheets.Add('Demo');

  ws.Cells.Item[1, 1].Value := 'Title';
  ws.MergeCells(1, 1, 1, 3);

  ws.ColWidth[1] := 24;          // widen column A
  ws.RowHeight[1] := 28;         // taller title row

  ws.Cells.Item[3, 1].Value := 'Visit losLab';
  ws.AddHyperlink(3, 1, 'https://www.loslab.com', 'losLab');

  ws.AddComment(3, 1, 'Vendor home page', 'Kevin');
  ws.AddTextBox('Standalone note', 2, 5, 5, 9);
  if ws.FindTextBoxAt(3, 6) <> nil then
    ws.DeleteTextBoxesInRange(2, 5, 5, 9);
end;
    

ดูเพิ่มเติม