TXLSXCell 是單一儲存格(值加上選填的公式與
格式索引);TXLSXCells 是透過 Worksheet.Cells
取得的各工作表集合,宣告於
lxHandleX
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;
end;
| 銷毀 | 釋放執行個體狀態並釋放擁有的資源 |
| SetWorkbook | 寫入所屬的活頁簿參照,使數值格式查閱等作業能以 O(1) 時間重複使用共用活頁簿集庫 |
| SetArrayRoot / SetArrayRange | 為陣列公式溢出錨點設定 ArrayRoot* 和 ArrayLast* 標記,以便一個根儲存格對應相同矩形中的所有相依儲存格 |
| 活頁簿 | 由工作表儲存格建立所設定的、指向擁有者 TXLSXWorkbook 的反向參照 |
| ArrayRootRow / ArrayRootCol / ArrayLastRow / ArrayLastCol | 陣列公式矩形的儲存/載入往返行程所使用的唯讀 CSE 溢出中繼資料 |
| Row | 從 1 開始的列索引 |
| Col | 從 1 開始的欄索引 (1 = A, 2 = B, ...) |
| 值 | 以 Variant 表示的儲存格值,支援字串、數字、布林值、
以及 TDateTime,未設定明確的 FormatIndex 時,設定
TDateTime 會自動採用內建的日期
cellXf (XlsxXfIndexDate) |
| FormatIndex | xl/styles.xml 中 cellXfs 的索引;預設格式請保留為 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 值 |
| 優先權 | 在同一個儲存格上設定多個 *Index 屬性時,SaveAs 端會依此順序選取相符的 cellXf:FormatIndex > FontIndex > FillIndex > BorderIndex > NumberFormatIndex |
| 公式 | 選用的公式文字(無前導 =);設定時,SaveAs 會與儲存格值一起發送 <f> 子元素,且 Open 會將其讀回 |
| ProtectionIndex | 活頁簿保護集區的索引;Locked 和 FormulaHidden 便利屬性會自動維護此索引以供常用 |
| Locked | 當為 True (所有新儲存格的預設值) 時,在工作表受保護的情況下該儲存格會受到保護;設定為 False 可允許編輯受保護工作表中的特定儲存格;與預設值不同時,會在該儲存格的 cellXf 中寫入 <protection locked="0"/> 屬性 |
| FormulaHidden | 當為 True 且工作表受保護時,公式列不會顯示該儲存格的公式;預設值為 False;這會在相符的 cellXf 中輸出 <protection hidden="1"/> |
| FormattedText | 唯讀 WideString;根據儲存格作用中的自訂或內建數值格式代碼,傳回格式化為字串的儲存格值 |
| TaggedText | 唯讀 WideString;在適用時,傳回包含富文字樣式之 HTML/XML 樣式格式化標籤的格式化儲存格字串 |
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;
| 建立 | 建構與一個所屬工作表繫結的儲存格集合 |
| 銷毀 | 釋放該集合擁有的所有儲存格 |
| Item[Row, Col] | 傳回給定以 1 為基底的座標處的儲存格,並在首次存取時建立一個空的 TXLSXCell;宣告為預設屬性,因此 Cells[Row, Col] 可作為簡寫 |
| 計數 | 目前儲存的儲存格數量 |
| CellByIndex[i] | 位於指定 0 起始插入索引的儲存格,適用於 在不事先得知已填入列與欄的情況下進行循序列舉 |
| 移除 | 刪除座標處的一個現有儲存格,並傳回 是否確實執行了移除 |
| 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;