Class OdfCell
- Namespace
- OdfKit.Spreadsheet
- Assembly
- OdfKit.dll
Represents a cell in an ODF spreadsheet. 表示 ODF 工作表中的一個儲存格。
public class OdfCell
- Inheritance
-
OdfCell
- Inherited Members
Remarks
Constructors
OdfCell(OdfNode, int, int, SpreadsheetDocument, string)
Represents a cell in an ODF spreadsheet. 表示 ODF 工作表中的一個儲存格。
public OdfCell(OdfNode node, int row, int col, SpreadsheetDocument doc, string sheetName = "")
Parameters
nodeOdfNodeThe cell XML node. / 儲存格 XML 節點。
rowintThe zero-based row index. / 採 0 為基準的列索引。
colintThe zero-based column index. / 採 0 為基準的欄索引。
docSpreadsheetDocumentThe spreadsheet document. / 試算表文件。
sheetNamestringThe containing sheet name. / 所在工作表名稱。
Remarks
Properties
CellValue
Gets or sets the commonly typed cell value. 取得或設定儲存格的常用型別值。
public object? CellValue { get; set; }
Property Value
Remarks
Date cells return DateTime when office:date-value can be parsed with
round-trip semantics; otherwise this accessor preserves the raw date string.
日期儲存格若可將 office:date-value 依 round-trip 語意解析,會回傳
DateTime;否則保留原始日期字串。
Column
Gets the zero-based column index. 取得以 0 為基準的欄索引。
public int Column { get; }
Property Value
CurrencyCode
Gets or sets the normalized ISO 4217 currency code stored in office:currency.
取得或設定儲存在 office:currency 的正規化 ISO 4217 貨幣代碼。
public string? CurrencyCode { get; set; }
Property Value
Remarks
Writing validates the ISO 4217 shape only — exactly three ASCII letters — and normalizes to
upper case. No list of currently assigned codes is enforced, because such a list would reject
historical codes, the XTS test code, and codes assigned after this release. Reading is
deliberately lenient: values already present in a loaded document are normalized but never rejected,
so documents written by other producers stay readable.
寫入時只驗證 ISO 4217 的形狀——恰好三個 ASCII 字母——並正規化為大寫;不比對現行代碼清單,
因為那會拒絕歷史代碼、XTS 測試代碼以及本版發佈後才配發的代碼。讀取刻意寬容:已存在於文件中的
值只做正規化而不拒絕,確保其他產生器寫出的文件仍可讀取。
Exceptions
- ArgumentException
Thrown when the value is not three ASCII letters. / 當值不是三個 ASCII 字母時擲出。
DisplayText
Gets or sets the displayed text content of the cell as plain text from text:p child nodes.
取得或設定儲存格顯示的文字內容(text:p 子節點的純文字)。
public string DisplayText { get; set; }
Property Value
FormattedValue
Gets the display value formatted by the applied number format style, or DisplayText when no style definition exists. 取得依套用數字格式樣式格式化後的顯示值;若無樣式定義則回傳 DisplayText。
public string FormattedValue { get; }
Property Value
Formula
Gets or sets the cell formula. 取得或設定儲存格的公式。
public string Formula { get; set; }
Property Value
RawValue
Gets or sets the raw numeric cell value as the office:value attribute string.
取得或設定儲存格的原始數值(office:value 屬性,字串格式)。
public string RawValue { get; set; }
Property Value
RichText
Gets the fluent rich text builder for this cell. 取得此儲存格的富文字鏈式建構器。
public OdfCellRichTextBuilder RichText { get; }
Property Value
Row
Gets the zero-based row index. 取得以 0 為基準的列索引。
public int Row { get; }
Property Value
Style
Gets the high-level style configuration facade for this cell. 取得此儲存格的高階樣式設定代理 Facade。
public OdfCellStyleProxy Style { get; }
Property Value
StyleName
Gets or sets the table style name applied to the cell. 取得或設定儲存格套用的表格樣式名稱。
public string? StyleName { get; set; }
Property Value
ValueType
Gets or sets the type of the cell data value. 取得或設定儲存格資料值的型態。
public string ValueType { get; set; }
Property Value
Methods
AddConditionalFormatMap(string, string)
Short overload of AddConditionalFormatMap that accepts condition and applyStyleName; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 condition 與 applyStyleName;其餘可選參數使用預設值並轉呼叫最長 AddConditionalFormatMap 多載。
public void AddConditionalFormatMap(string condition, string applyStyleName)
Parameters
AddConditionalFormatMap(string, string, OdfCellAddress?)
Adds a conditional formatting map rule. 新增條件格式對應規則。
public void AddConditionalFormatMap(string condition, string applyStyleName, OdfCellAddress? baseCell)
Parameters
conditionstringThe condition value, such as
cell-content()=1. / 條件值,例如cell-content()=1。applyStyleNamestringThe formatting style name to apply. / 要套用的格式樣式名稱。
baseCellOdfCellAddress?The base cell address. / 基準儲存格位址。
AppendHtml(string)
Parses and appends an HTML inline rich text fragment to the end of the cell text. 在儲存格文字結尾解析並追加 HTML 行內富文字片段。
public OdfCell AppendHtml(string html)
Parameters
htmlstringThe HTML inline fragment to parse. / 要解析的 HTML 行內片段。
Returns
- OdfCell
The current cell for chaining. / 目前儲存格,方便鏈式呼叫。
AppendMarkdown(string)
Parses and appends a Markdown inline rich text fragment to the end of the cell text. 在儲存格文字結尾解析並追加 Markdown 行內富文字片段。
public OdfCell AppendMarkdown(string markdown)
Parameters
markdownstringThe Markdown inline text to parse. / 要解析的 Markdown 行內文字。
Returns
- OdfCell
The current cell for chaining. / 目前儲存格,方便鏈式呼叫。
FindAnnotation()
Finds the cell annotation, or null when no annotation exists. 尋找儲存格的批注;若無批注則回傳 null。
public OdfCellAnnotation? FindAnnotation()
Returns
GetHyperlinkUrl()
Gets the hyperlink URL of the cell, or null when no hyperlink exists. 取得儲存格的超連結 URL;若無超連結則回傳 null。
public string? GetHyperlinkUrl()
Returns
GetRichText()
Gets the rich text content of the cell, or null when it is plain text or empty. 取得儲存格的富文字內容;若為純文字或空白則回傳 null。
public OdfRichText? GetRichText()
Returns
GetValue<T>()
Gets the cell value as the specified type T, returning the default value when conversion fails.
以指定型別 T 取得儲存格值;轉換失敗時回傳預設值。
public T? GetValue<T>()
Returns
- T
The converted cell value, or the default value when conversion fails. / 轉換後的儲存格值;轉換失敗時為預設值。
Type Parameters
TThe target value type. / 目標值型別。
Remarks
When a date cell can round-trip parse office:date-value, GetValue<T>() first reuses
the parsed DateTime from CellValue. Therefore GetValue<DateTime>()
preserves the parsed instant, while GetValue<string>() converts that
DateTime with InvariantCulture instead of returning the raw ISO text.
若日期儲存格的 office:date-value 可依 round-trip 語意解析,GetValue<T>()
會先重用 CellValue 產生的 DateTime;因此 GetValue<DateTime>()
會保留解析後的時間點,而 GetValue<string>() 會以
InvariantCulture 將該 DateTime 轉成字串,而非回傳原始 ISO 文字。
RemoveAnnotation()
Removes the cell annotation. 移除儲存格的批注。
public bool RemoveAnnotation()
Returns
RemoveHyperlink()
Removes the hyperlink of the cell while preserving display text. 移除儲存格的超連結,保留顯示文字。
public bool RemoveHyperlink()
Returns
SetAnnotation(string)
Short overload of SetAnnotation that accepts text; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 text;其餘可選參數使用預設值並轉呼叫最長 SetAnnotation 多載。
public void SetAnnotation(string text)
Parameters
textstring
SetAnnotation(string, string?)
Short overload of SetAnnotation that accepts text and author; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 text 與 author;其餘可選參數使用預設值並轉呼叫最長 SetAnnotation 多載。
public void SetAnnotation(string text, string? author)
Parameters
SetAnnotation(string, string?, bool)
Sets the cell annotation and overwrites any existing annotation. 設定儲存格的批注。若已有批注則覆蓋。
public void SetAnnotation(string text, string? author, bool visible)
Parameters
textstringThe annotation content. / 批注內容。
authorstringThe author name. / 作者名稱。
visibleboolWhether to display the annotation; the default is false. / 是否顯示;預設為 false。
SetBorders(OdfBorder?, OdfBorder?, OdfBorder?, OdfBorder?)
Sets the border style for all four sides of this cell. 設定此儲存格的四面框線樣式。
public void SetBorders(OdfBorder? top, OdfBorder? bottom, OdfBorder? left, OdfBorder? right)
Parameters
topOdfBorder?The top border. / 上框線。
bottomOdfBorder?The bottom border. / 下框線。
leftOdfBorder?The left border. / 左框線。
rightOdfBorder?The right border. / 右框線。
SetCurrencyValue(decimal, string)
Sets the currency value of the cell. 設定儲存格的貨幣值。
public void SetCurrencyValue(decimal amount, string currencyCode)
Parameters
amountdecimalThe numeric amount stored in
office:value. / 儲存在office:value的數值金額。currencyCodestringThe ISO 4217 currency code. / ISO 4217 貨幣代碼。
SetCurrencyValue(decimal, string, string)
Sets the currency value and display text of the cell. 設定儲存格的貨幣值與顯示文字。
public void SetCurrencyValue(decimal amount, string currencyCode, string displayText)
Parameters
amountdecimalThe numeric amount stored in
office:value. / 儲存在office:value的數值金額。currencyCodestringThe ISO 4217 currency code. / ISO 4217 貨幣代碼。
displayTextstringThe plain-text display value written into
text:p. / 寫入text:p的純文字顯示值。
Exceptions
- ArgumentException
Thrown when
currencyCodeis not three ASCII letters. / 當currencyCode不是三個 ASCII 字母時擲出。
SetFormula(string, object?)
Sets this cell's formula and cached display value. 設定此儲存格的公式與快取顯示值。
public void SetFormula(string formula, object? cachedValue)
Parameters
formulastringThe ODF formula text; an empty value clears the formula. / ODF 公式文字;空值會清除公式。
cachedValueobjectThe cached value stored with the formula. / 隨公式儲存的快取值。
SetHyperlink(string)
Short overload of SetHyperlink that accepts url; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 url;其餘可選參數使用預設值並轉呼叫最長 SetHyperlink 多載。
public void SetHyperlink(string url)
Parameters
urlstring
SetHyperlink(string, string?)
Sets the hyperlink of the cell. 設定儲存格的超連結。
public void SetHyperlink(string url, string? displayText)
Parameters
urlstringThe hyperlink URL. / 超連結 URL。
displayTextstringThe link display text; when null, the existing text content or URL itself is used. / 連結顯示文字;為 null 時使用現有文字內容或 URL 本身。
SetRichText(OdfRichText)
Sets the rich text content of the cell and replaces existing text. 設定儲存格的富文字內容,取代現有文字。
public void SetRichText(OdfRichText richText)
Parameters
richTextOdfRichTextThe rich text content to write to the cell. / 要寫入儲存格的富文字內容。
SetText(string, OdfTextFontFallbackOptions)
Sets text with the specified font fallback options. 使用指定的字型遞補選項設定文字。
public void SetText(string text, OdfTextFontFallbackOptions options)
Parameters
textstringThe text content to write. / 要寫入的文字內容。
optionsOdfTextFontFallbackOptionsThe font fallback options. / 字型遞補選項。
SetValue(bool)
Sets the Boolean value of the cell. 設定儲存格的布林值。
public void SetValue(bool val)
Parameters
valboolThe Boolean value. / 布林值。
SetValue(DateTime)
Short overload of SetValue that accepts date; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 date;其餘可選參數使用預設值並轉呼叫最長 SetValue 多載。
public void SetValue(DateTime date)
Parameters
dateDateTime
SetValue(DateTime, bool)
Sets the date and time value of the cell. 設定儲存格的日期時間值。
public void SetValue(DateTime date, bool useTimezoneNaive)
Parameters
dateDateTimeThe date and time value. / 日期時間。
useTimezoneNaiveboolWhether to ignore time zone conversion and use local time formatting. / 是否忽略時區轉換,使用當地時間格式。
SetValue(double)
Sets the numeric value of the cell. 設定儲存格的數值。
public void SetValue(double val)
Parameters
valdoubleThe numeric value. / 數值。
SetValue(string)
Sets the text content of the cell. 設定儲存格的文字內容。
public void SetValue(string text)
Parameters
textstringThe text string. / 文字字串。