Class Cell
public sealed class Cell
- Inheritance
-
Cell
- Inherited Members
Constructors
Cell(Cell, SheetData, WorkbookPart)
Initializes a new instance of the Cell class.
public Cell(Cell cell, SheetData sheetData, WorkbookPart workbookPart)
Parameters
cellCellThe underlying OpenXML cell object.
sheetDataSheetDataThe sheet data containing the cell.
workbookPartWorkbookPart
Exceptions
- ArgumentNullException
Thrown when
cellorsheetDatais null.
Properties
CellReference
Gets the cell reference in A1 notation.
public string CellReference { get; }
Property Value
Methods
ApplyStyle(uint)
Applies a style to the cell.
public void ApplyStyle(uint styleIndex)
Parameters
styleIndexuintThe index of the style to apply.
GetDataType()
Gets the data type of the cell's value.
public CellValues? GetDataType()
Returns
- CellValues?
The cell's value data type, or null if not set.
GetFormula()
Gets the formula set for the cell.
public string GetFormula()
Returns
- string
The cell's formula as a string, or null if not set.
GetValue()
Gets the value of the cell.
public string GetValue()
Returns
- string
The cell value as a string.
PutFormula(string)
Sets a formula for the cell.
public void PutFormula(string formula)
Parameters
formulastringThe formula to set.
PutValue(DateTime)
Sets the value of the cell as a date.
public void PutValue(DateTime value)
Parameters
valueDateTimeThe date value to set.
PutValue(double)
Sets the value of the cell as a number.
public void PutValue(double value)
Parameters
valuedoubleThe numeric value to set.
PutValue(string)
Sets the value of the cell as a string.
public void PutValue(string value)
Parameters
valuestringThe value to set.
SetHyperlink(string, string)
Adds a hyperlink to the specified cell with an optional tooltip.
public void SetHyperlink(string hyperlinkUrl, string tooltip = null)
Parameters
hyperlinkUrlstringThe URL of the hyperlink to be added.
tooltipstringThe optional tooltip to display when hovering over the hyperlink.
Examples
The following example demonstrates how to use the SetHyperlink method:
using (Workbook wb = new Workbook("path/to/your/file.xlsx"))
{
Worksheet sheet = wb.Worksheets[0];
Cell cell = sheet.Cells["A1"];
cell.PutValue("Click Me");
cell.SetHyperlink("https://example.com", "Visit Example");
wb.Save("path/to/your/file.xlsx");
}
Remarks
This method creates a hyperlink relationship in the parent worksheet and adds a Hyperlink element to the cell's reference in the worksheet. The method does not modify the cell's text; use PutValue(string) to set display text if needed.
Exceptions
- ArgumentException
Thrown when
hyperlinkUrlis null or empty.- InvalidOperationException
Thrown when the parent WorksheetPart or the OpenXML Worksheet cannot be found.