Table of Contents

Class Cell

Namespace
Openize.Cells
Assembly
Openize.OpenXMLSDK.dll
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

cell Cell

The underlying OpenXML cell object.

sheetData SheetData

The sheet data containing the cell.

workbookPart WorkbookPart

Exceptions

ArgumentNullException

Thrown when cell or sheetData is null.

Properties

CellReference

Gets the cell reference in A1 notation.

public string CellReference { get; }

Property Value

string

Methods

ApplyStyle(uint)

Applies a style to the cell.

public void ApplyStyle(uint styleIndex)

Parameters

styleIndex uint

The 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

formula string

The formula to set.

PutValue(DateTime)

Sets the value of the cell as a date.

public void PutValue(DateTime value)

Parameters

value DateTime

The date value to set.

PutValue(double)

Sets the value of the cell as a number.

public void PutValue(double value)

Parameters

value double

The numeric value to set.

PutValue(string)

Sets the value of the cell as a string.

public void PutValue(string value)

Parameters

value string

The value to set.

Adds a hyperlink to the specified cell with an optional tooltip.

public void SetHyperlink(string hyperlinkUrl, string tooltip = null)

Parameters

hyperlinkUrl string

The URL of the hyperlink to be added.

tooltip string

The optional tooltip to display when hovering over the hyperlink.

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");
}

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 hyperlinkUrl is null or empty.

InvalidOperationException

Thrown when the parent WorksheetPart or the OpenXML Worksheet cannot be found.