Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Struct

ExcelCell

OfficeIMO.Excel

Namespace
OfficeIMO.Excel
Assembly
OfficeIMO.Excel
Source revision
c47203b3ce89 with working tree changes
Base
ValueType
Implements
IEquatable<ExcelCell>
Modifiers
sealed

A worksheet cell handle: the sheet plus a 1-based row and column. It stores no cell state, so creating one in a loop allocates nothing; every member reads or writes the worksheet directly.

Inheritance

  • ValueType
  • ExcelCell

Usage

Explore 36 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Accepted by parameters 5

Methods

public ExcelCell Clear(ExcelClearOptions options = All) #

Clears selected cell data and metadata.

Parameters

options OfficeIMO.Excel.ExcelClearOptions = All optional

Returns

ExcelCell
Equals 2 overloads
public bool Equals(ExcelCell other) #

Returns whether both handles address the same cell of the same worksheet object.

Parameters

other OfficeIMO.Excel.ExcelCell required

Returns

bool
public override bool Equals(object? obj) #

Indicates whether this instance and a specified object are equal.

Parameters

obj object? required
The object to compare with the current instance.

Returns

bool true if obj and this instance are the same type and represent the same value; otherwise, false.
public string GetFormattedText(IFormatProvider? provider = null) #

Gets formatted display text for the cell value.

Parameters

provider System.IFormatProvider? = null optional

Returns

string
public override int GetHashCode() #

Returns the hash code for this instance.

Returns

int A 32-bit signed integer that is the hash code for this instance.
public IReadOnlyList<ExcelRichTextRun> GetRichText() #

Gets rich inline text runs from the cell.

Returns

IReadOnlyList<ExcelRichTextRun>
public ExcelCellStyleInfo GetStyle() #

Gets a read-only snapshot of the cell's visual style.

public ExcelCellData GetValue() #

Gets a typed snapshot of the cell value.

public T? GetValue<T>() #

Gets the cell value converted to the requested type.

Type Parameters

T

Returns

T?
public static bool op_Equality(ExcelCell left, ExcelCell right) #

Returns whether both handles address the same cell.

Parameters

left OfficeIMO.Excel.ExcelCell required
right OfficeIMO.Excel.ExcelCell required

Returns

bool
public static bool op_Inequality(ExcelCell left, ExcelCell right) #

Returns whether the handles address different cells.

Parameters

left OfficeIMO.Excel.ExcelCell required
right OfficeIMO.Excel.ExcelCell required

Returns

bool
public ExcelCell SetBaseline() #

Restores the cell text to the normal baseline.

Returns

ExcelCell
public ExcelCell SetBold(bool bold = true) #

Sets or clears bold font style.

Parameters

bold bool = true optional

Returns

ExcelCell
SetBorder 2 overloads
public ExcelCell SetBorder(ExcelBorderStyle style, OfficeColor? color = null) #

Applies a border style to the cell.

Parameters

style OfficeIMO.Excel.ExcelBorderStyle required
color OfficeIMO.OfficeColor? = null optional

Returns

ExcelCell
public ExcelCell SetBorder(ExcelCellBorders borders, ExcelBorderStyle style, OfficeColor? color = null) #

Sets selected border edges while preserving other edges and cell styles.

Parameters

borders OfficeIMO.Excel.ExcelCellBorders required
style OfficeIMO.Excel.ExcelBorderStyle required
color OfficeIMO.OfficeColor? = null optional

Returns

ExcelCell
public ExcelCell SetColor(OfficeColor color) #

Sets the font color using a hex color value.

Parameters

color OfficeIMO.OfficeColor required

Returns

ExcelCell
public ExcelCell SetDiagonalBorder(ExcelBorderStyle style, OfficeColor? color = null, bool diagonalUp = true, bool diagonalDown = true) #

Applies diagonal borders to the cell.

Parameters

style OfficeIMO.Excel.ExcelBorderStyle required
color OfficeIMO.OfficeColor? = null optional
diagonalUp bool = true optional
diagonalDown bool = true optional

Returns

ExcelCell
public ExcelCell SetError(string errorText) #

Writes a native Excel error value, such as #N/A or #DIV/0!.

Parameters

errorText string required

Returns

ExcelCell
public ExcelCell SetFillColor(OfficeColor color) #

Sets the solid fill color. Theme colors stay linked to the workbook theme.

Parameters

color OfficeIMO.OfficeColor required

Returns

ExcelCell
public ExcelCell SetFontFamily(string fontFamily) #

Sets the font family name.

Parameters

fontFamily string required

Returns

ExcelCell
public ExcelCell SetFontSize(OfficeLength fontSize) #

Sets a positive physical font size.

Parameters

fontSize OfficeIMO.OfficeLength required

Returns

ExcelCell
public ExcelCell SetFormula(string formula) #

Sets the cell formula while keeping any existing value as its cached result. This is not a redaction API: rebuild the workbook from approved data to remove sensitive historic content.

Parameters

formula string required

Returns

ExcelCell
public ExcelCell SetGradientFill(OfficeColor fromColor, OfficeColor toColor, double degree = 0) #

Sets a two-color linear gradient fill using literal or theme colors.

Parameters

fromColor OfficeIMO.OfficeColor required
toColor OfficeIMO.OfficeColor required
degree double = 0 optional

Returns

ExcelCell
public ExcelCell SetHorizontalAlignment(ExcelHorizontalAlignment alignment) #

Sets the horizontal alignment.

Parameters

alignment OfficeIMO.Excel.ExcelHorizontalAlignment required

Returns

ExcelCell
public ExcelCell SetItalic(bool italic = true) #

Sets or clears italic font style.

Parameters

italic bool = true optional

Returns

ExcelCell
public ExcelCell SetNumberFormat(string numberFormat) #

Applies a number format to the cell.

Parameters

numberFormat string required

Returns

ExcelCell
SetRichText 2 overloads
public ExcelCell SetRichText(params ExcelRichTextRun[] runs) #

Replaces the cell contents with rich inline text runs.

Parameters

runs OfficeIMO.Excel.ExcelRichTextRun[] required

Returns

ExcelCell
public ExcelCell SetRichText(IEnumerable<ExcelRichTextRun> runs) #

Replaces the cell contents with rich inline text runs.

Parameters

runs System.Collections.Generic.IEnumerable<OfficeIMO.Excel.ExcelRichTextRun> required

Returns

ExcelCell
public ExcelCell SetShrinkToFit(bool shrinkToFit = true) #

Sets or clears shrink-to-fit text alignment.

Parameters

shrinkToFit bool = true optional

Returns

ExcelCell
public ExcelCell SetStrikethrough(bool strikethrough = true) #

Sets or clears strikethrough font style.

Parameters

strikethrough bool = true optional

Returns

ExcelCell
public ExcelCell SetSubscript() #

Formats the cell text as subscript.

Returns

ExcelCell
public ExcelCell SetSuperscript() #

Formats the cell text as superscript.

Returns

ExcelCell
public ExcelCell SetTextRotation(int rotation) #

Sets Excel text rotation. Use 0-90 for upward rotation, 91-180 for downward rotation, or 255 for stacked vertical text.

Parameters

rotation int required

Returns

ExcelCell
SetUnderline 2 overloads
public ExcelCell SetUnderline(bool underline = true) #

Sets or clears underline font style.

Parameters

underline bool = true optional

Returns

ExcelCell
public ExcelCell SetUnderline(ExcelUnderlineStyle underlineStyle) #

Sets the native Excel underline style.

Parameters

underlineStyle OfficeIMO.Excel.ExcelUnderlineStyle required

Returns

ExcelCell
SetValue 19 overloads
public ExcelCell SetValue(object? value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value object? required

Returns

ExcelCell
public ExcelCell SetValue(string value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value string required

Returns

ExcelCell
public ExcelCell SetValue(double value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value double required

Returns

ExcelCell
public ExcelCell SetValue(float value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value float required

Returns

ExcelCell
public ExcelCell SetValue(decimal value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value decimal required

Returns

ExcelCell
public ExcelCell SetValue(int value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value int required

Returns

ExcelCell
public ExcelCell SetValue(long value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value long required

Returns

ExcelCell
public ExcelCell SetValue(short value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value short required

Returns

ExcelCell
public ExcelCell SetValue(uint value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value uint required

Returns

ExcelCell
public ExcelCell SetValue(ulong value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value ulong required

Returns

ExcelCell
public ExcelCell SetValue(ushort value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value ushort required

Returns

ExcelCell
public ExcelCell SetValue(byte value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value byte required

Returns

ExcelCell
public ExcelCell SetValue(sbyte value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value sbyte required

Returns

ExcelCell
public ExcelCell SetValue(bool value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value bool required

Returns

ExcelCell
public ExcelCell SetValue(DateTime value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value System.DateTime required

Returns

ExcelCell
public ExcelCell SetValue(DateTimeOffset value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value System.DateTimeOffset required

Returns

ExcelCell
public ExcelCell SetValue(TimeSpan value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value System.TimeSpan required

Returns

ExcelCell
public ExcelCell SetValue(DateOnly value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value System.DateOnly required

Returns

ExcelCell
public ExcelCell SetValue(TimeOnly value) #

Sets the cell value, inferring the stored type. Dates and times get a date or duration number format unless the cell already has one.

Parameters

value System.TimeOnly required

Returns

ExcelCell
public ExcelCell SetValue<T>(T? value) #

Sets the cell value from a nullable value; null writes an empty value.

Type Parameters

T

Parameters

value T? required

Returns

ExcelCell
public ExcelCell SetVerticalAlignment(ExcelVerticalAlignment alignment) #

Sets the vertical alignment.

Parameters

alignment OfficeIMO.Excel.ExcelVerticalAlignment required

Returns

ExcelCell
public ExcelCell SetVerticalTextAlignment(ExcelVerticalTextAlignment alignment) #

Sets the native Excel baseline, superscript, or subscript alignment.

Parameters

alignment OfficeIMO.Excel.ExcelVerticalTextAlignment required

Returns

ExcelCell
public ExcelCell SetWrapText(bool wrapText = true) #

Sets or clears text wrapping.

Parameters

wrapText bool = true optional

Returns

ExcelCell
public ExcelCell TransformTextCase(OfficeTextCase textCase, CultureInfo? culture = null) #

Changes stored text casing while preserving cell or rich-run formatting. Formulas and non-text values are left unchanged.

Parameters

textCase OfficeIMO.Drawing.OfficeTextCase required
culture System.Globalization.CultureInfo? = null optional

Returns

ExcelCell
public bool TryGetValue<T>(out T? value) #

Tries to get the cell value converted to the requested type.

Type Parameters

T

Parameters

value T? required

Returns

bool

Properties

public ExcelSheet Sheet { get; } #

Gets the worksheet that owns the cell.

Exceptions

  • InvalidOperationException – The handle is default and has no worksheet.
public int Row { get; } #

Gets the 1-based row index.

public int Column { get; } #

Gets the 1-based column index.

public string Address { get; } #

Gets the A1 cell address.