HotXLS 文件

TXLSXCell / TXLSXCells 類別

在 TXLSXWorksheetTXLSXCell 是單一儲存格(值加上選填的公式與 格式索引); TXLSXCells 是透過 Worksheet.Cells取得的各工作表集合,宣告於 lxHandleX

TXLSXCell 宣告

type
  TXLSXCell = class
    constructor Create(ARow, ACol: Integer; const AValue: Variant);
    destructor Destroy; override;
    procedure SetWorkbook(AWorkbook: TXLSXWorkbook);
    procedure SetArrayRoot(ARootRow, ARootCol: Integer);
    procedure SetArrayRange(ARootRow, ARootCol, ALastRow, ALastCol: Integer);
    property Workbook: TXLSXWorkbook;
    property ArrayRootRow: Integer;
    property ArrayRootCol: Integer;
    property ArrayLastRow: Integer;
    property ArrayLastCol: Integer;
    property Row: Integer;
    property Col: Integer;
    property Value: Variant;
    property FormatIndex: Integer;
    property FontIndex: Integer;
    property FillIndex: Integer;
    property BorderIndex: Integer;
    property NumberFormatIndex: Integer;
    property NumberFormat: WideString;
    property AlignmentIndex: Integer;
    property ProtectionIndex: Integer;
    property Formula: WideString;
    property RichText: TXLSXRichText;
    property Locked: Boolean;
    property FormulaHidden: Boolean;
    property FormattedText: WideString;
    property TaggedText: WideString;
    property NamedStyleXfId: Integer;
    property LinkedStyle: TXLSXLinkedStyle;
  end;
      

TXLSXCell 成員

Destroy釋放執行個體狀態並釋放擁有的資源
SetWorkbook寫入所屬的活頁簿參照,使數值格式查閱等作業能以 O(1) 時間重複使用共用活頁簿集庫
SetArrayRoot / SetArrayRange為陣列公式溢出錨點設定 ArrayRoot* 和 ArrayLast* 標記,以便一個根儲存格對應相同矩形中的所有相依儲存格
Workbook由工作表儲存格建立所設定的、指向擁有者 TXLSXWorkbook 的反向參照
ArrayRootRow / ArrayRootCol / ArrayLastRow / ArrayLastCol陣列公式矩形的儲存/載入往返行程所使用的唯讀 CSE 溢出中繼資料
Row從 1 開始的列索引
Col從 1 開始的欄索引 (1 = A, 2 = B, ...)
Value以 Variant 表示的儲存格值,支援字串、數字、布林值、 以及 TDateTime ,未設定明確的 TDateTime 時,設定 cellXf 會自動採用內建的日期XlsxXfIndexDate( FormatIndex )
FormatIndexIndex into xl/styles.xmlcellXfs 中 0 的索引;預設格式請保留為 1 ;索引numFmtId 14保留給內建的日期格式 ( m/d/yyyy, FormatIndex );設定時,在發送的儲存格中, FontIndex 的優先權高於
FontIndex從 1 開始的索引,指向 TXLSXWorkbook.Fonts 保留為 0 以繼承預設的 Calibri 11
FillIndex從 1 開始的索引,指向 TXLSXWorkbook.Fills 請參閱 TXLSXFill
BorderIndex從 1 開始的索引,指向 TXLSXWorkbook.Borders 請參閱 TXLSXBorder
NumberFormatIndex從 1 開始的索引,指向 TXLSXWorkbook.NumberFormats 可用於自訂格式代碼,例如 '$#,##0.00' 或 'yyyy-mm-dd hh:mm:ss'
NumberFormat自訂數值格式文字的便利屬性 當 NumberFormatIndex 指向某個格式時,讀取會傳回活頁簿數值格式集中的格式代碼;指派字串 會尋找或附加格式並更新 NumberFormatIndex
AlignmentIndex從 1 開始的索引,指向 TXLSXWorkbook.Alignments 請參閱 TXLSXAlignment 以瞭解各個項目的水平 / 垂直 / 自動換行 / 縮排 / 旋轉等設定
RichText選用擁有的 TXLSXRichText 承載;設定時,儲存格會作為多區段 <si> 項目通過共用字串表,而不是單純的字串;指派 nil 會還原為儲存格的 Variant 值
Precedence在同一個儲存格上設定多個 *Index 屬性時,SaveAs 端會依此順序選取相符的 cellXf: FormatIndex > FontIndex > FillIndex > BorderIndex > NumberFormatIndex
Formula選用的公式文字(無前導 =);設定時, SaveAs 會與儲存格值一起發送 <f> 子元素,且 Open 會將其讀回
ProtectionIndex活頁簿保護集區的索引; Locked 和 FormulaHidden 便利屬性會自動維護此索引以供常用
Locked當為 True (所有新儲存格的預設值) 時,在工作表受保護的情況下該儲存格會受到保護;設定為 False 可允許編輯受保護工作表中的特定儲存格;與預設值不同時,會在該儲存格的 <protection locked="0"/> 中寫入 cellXf 屬性
FormulaHidden當為 True且工作表受保護時,公式列不會顯示該儲存格的公式;預設值為 False;這會在相符的 <protection hidden="1"/> 中輸出 cellXf
FormattedText唯讀 WideString;根據儲存格作用中的自訂或內建數值格式代碼,傳回格式化為字串的儲存格值
TaggedText唯讀 WideString;在適用時,傳回包含富文字樣式之 HTML/XML 樣式格式化標籤的格式化儲存格字串
NamedStyleXfId唯讀 Integer;傳回此儲存格所連結具名樣式的 cellXfs 索引,儲存格沒有樣式承載時為 -1 when the cell has no style payload
LinkedStyle可讀寫的 TXLSXLinkedStyle 記錄。把儲存格連結到具名樣式: AutomaticChoose 讓 Excel 自動挑選樣式, LinkedParts 則選擇哪些格式部分(字型、填滿、框線、數值格式、對齊、保護)跟隨連結的樣式

TXLSXCells 宣告

type
  TXLSXCells = class
    constructor Create(AOwnerSheet: TXLSXWorksheet);
    destructor Destroy; override;
    procedure Clear;
    function HasCell(ARow, ACol: Integer): Boolean;
    function Remove(ARow, ACol: Integer): Boolean;
    property Item[ARow, ACol: Integer]: TXLSXCell; default;
    property Count: Integer;
    property CellByIndex[Index: Integer]: TXLSXCell;
  end;
      

TXLSXCells 成員

Create建構與一個所屬工作表繫結的儲存格集合
Destroy釋放該集合擁有的所有儲存格
Item[Row, Col]傳回給定以 1 為基底的座標處的儲存格,並在首次存取時建立一個空的 TXLSXCell ;宣告為預設屬性,因此 Cells[Row, Col] 可作為簡寫
Count目前儲存的儲存格數量
CellByIndex[i]位於指定 0 起始插入索引的儲存格,適用於 在不事先得知已填入列與欄的情況下進行循序列舉
Remove刪除座標處的一個現有儲存格,並傳回 是否確實執行了移除
HasCell(Row, Col)如果給定座標處已存在儲存格,則傳回 True ;使用此方法可避免因 Item[Row, Col]
Clear移除並釋放集合中的每個儲存格

範例

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

  ws.Cells.Item[1, 1].Value := 'Hello';
  ws.Cells.Item[1, 2].Value := 123.45;
  ws.Cells.Item[2, 1].Value := Now;             // renders as a date
  ws.Cells.Item[2, 2].Formula := 'SUM(B1:B1)';

  for i := 0 to ws.Cells.Count - 1 do
    WriteLn(ws.Cells.CellByIndex[i].Row, ',',
            ws.Cells.CellByIndex[i].Col);
end;
    

請參閱