Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

ExcelRange

OfficeIMO.Excel

Namespace
OfficeIMO.Excel
Assembly
OfficeIMO.Excel
Source revision
c47203b3ce89 with working tree changes
Modifiers
sealed

Lightweight object model wrapper for an A1 range: a cell, a rectangle, whole rows or columns, or a list of such areas separated by spaces or commas.

Inheritance

  • object
  • ExcelRange

Remarks

A range with several areas formats every cell of every area and carries its conditional formatting and data validation as one rule. Operations that need one rectangle, such as merging, copying, sorting, tables, values and AutoFilter, throw for it.

Usage

Explore 42 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.

Methods

public ExcelAutoFilter AutoFilter() #

Returns the AutoFilter on this range, creating it when the range has none. An existing filter on the same range keeps its criteria; a worksheet filter on another range is replaced. A table on the same range owns the filter.

public ExcelCell Cell(int rowOffset, int columnOffset) #

Gets an editable cell using one-based offsets from this range's top-left cell.

Parameters

rowOffset int required
columnOffset int required

Returns

ExcelCell
public ExcelRange Clear(ExcelClearOptions options = All) #

Clears selected data and metadata from the range.

Parameters

options OfficeIMO.Excel.ExcelClearOptions = All optional

Returns

ExcelRange
public ExcelRangeConditionalFormattingBuilder ConditionalFormat() #

Adds conditional formatting rules to the range.

public ExcelMutationResult CopyTo(string destinationTopLeft, ExcelMutationPlanOptions? options = null, CancellationToken cancellationToken = default) #

Copies this range to a destination top-left cell.

Parameters

destinationTopLeft string required
options OfficeIMO.Excel.ExcelMutationPlanOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public ExcelTable CreateTable(string name, bool hasHeader = true, ExcelTableStyle style = TableStyleMedium2, bool includeAutoFilter = true) #

Creates an Excel table over the range.

Parameters

name string required
hasHeader bool = true optional
style OfficeIMO.Excel.ExcelTableStyle = TableStyleMedium2 optional
includeAutoFilter bool = true optional

Returns

ExcelTable
public ExcelRangeVisualInfo CreateVisualSnapshot(ExcelImageExportOptions? options = null) #

Creates a format-neutral visual snapshot for this range.

Parameters

options OfficeIMO.Excel.ExcelImageExportOptions? = null optional
public ExcelMutationResult Delete(ExcelCellShiftDirection direction, ExcelMutationPlanOptions? options = null, CancellationToken cancellationToken = default) #

Transactionally deletes this cell block.

Parameters

direction OfficeIMO.Excel.ExcelCellShiftDirection required
options OfficeIMO.Excel.ExcelMutationPlanOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public OfficeImageExportResult ExportImage(OfficeImageExportFormat format, ExcelImageExportOptions? options = null, CancellationToken cancellationToken = default) #

Exports this range as a supported raster format or SVG.

Parameters

format OfficeIMO.Drawing.OfficeImageExportFormat required
options OfficeIMO.Excel.ExcelImageExportOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

OfficeImageExportResult
public ExcelMutationResult Insert(ExcelCellShiftDirection direction, ExcelMutationPlanOptions? options = null, CancellationToken cancellationToken = default) #

Transactionally inserts a cell block at this range.

Parameters

direction OfficeIMO.Excel.ExcelCellShiftDirection required
options OfficeIMO.Excel.ExcelMutationPlanOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public ExcelRange Merge() #

Merges the range.

Returns

ExcelRange
public ExcelMutationResult MoveTo(string destinationTopLeft, ExcelMutationPlanOptions? options = null, CancellationToken cancellationToken = default) #

Moves this range to a destination top-left cell.

Parameters

destinationTopLeft string required
options OfficeIMO.Excel.ExcelMutationPlanOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
SaveAsImage 2 overloads
public OfficeConversionReport SaveAsImage(string path, ExcelImageExportOptions? options = null, CancellationToken cancellationToken = default) #

Writes the range to a file and returns its fidelity report.

Parameters

path string required
options OfficeIMO.Excel.ExcelImageExportOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

OfficeConversionReport
public OfficeConversionReport SaveAsImage(Stream stream, ExcelImageExportOptions? options = null, CancellationToken cancellationToken = default) #

Writes the range to a caller-owned stream and returns its fidelity report.

Parameters

stream System.IO.Stream required
options OfficeIMO.Excel.ExcelImageExportOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

OfficeConversionReport
SaveAsImageAsync 2 overloads
public async Task<OfficeConversionReport> SaveAsImageAsync(string path, ExcelImageExportOptions? options = null, CancellationToken cancellationToken = default) #

Asynchronously writes the range to a file and returns its fidelity report.

Parameters

path string required
options OfficeIMO.Excel.ExcelImageExportOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task<OfficeConversionReport>
public async Task<OfficeConversionReport> SaveAsImageAsync(Stream stream, ExcelImageExportOptions? options = null, CancellationToken cancellationToken = default) #

Asynchronously writes the range to a caller-owned stream and returns its fidelity report.

Parameters

stream System.IO.Stream required
options OfficeIMO.Excel.ExcelImageExportOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task<OfficeConversionReport>
public ExcelRange SetBaseline() #

Restores every cell in the range to the normal baseline.

Returns

ExcelRange
public ExcelRange SetBold(bool bold = true) #

Sets or clears bold font style for every cell in the range.

Parameters

bold bool = true optional

Returns

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

Applies a border style to every edge of every cell in the range.

Parameters

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

Returns

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

Sets selected border edges of every cell in the range while preserving other edges and styles.

Parameters

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

Returns

ExcelRange
public ExcelRange SetColor(OfficeColor color) #

Applies a font color to every cell in the range.

Parameters

color OfficeIMO.OfficeColor required

Returns

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

Applies diagonal borders to every cell in the range.

Parameters

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

Returns

ExcelRange
public ExcelRange SetFillColor(OfficeColor color) #

Applies a solid fill color to every cell in the range. Theme colors stay linked to the workbook theme.

Parameters

color OfficeIMO.OfficeColor required

Returns

ExcelRange
public ExcelRange SetFontFamily(string fontFamily) #

Applies a font family name to every cell in the range.

Parameters

fontFamily string required

Returns

ExcelRange
public ExcelRange SetFontSize(OfficeLength fontSize) #

Applies a positive physical font size to every cell in the range.

Parameters

fontSize OfficeIMO.OfficeLength required

Returns

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

Applies a two-color linear gradient fill to every cell in the range.

Parameters

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

Returns

ExcelRange
public ExcelRange SetHorizontalAlignment(ExcelHorizontalAlignment alignment) #

Sets the horizontal alignment of every cell in the range.

Parameters

alignment OfficeIMO.Excel.ExcelHorizontalAlignment required

Returns

ExcelRange
public ExcelRange SetItalic(bool italic = true) #

Sets or clears italic font style for every cell in the range.

Parameters

italic bool = true optional

Returns

ExcelRange
public ExcelRange SetNumberFormat(string numberFormat) #

Applies a number format to every cell in the range.

Parameters

numberFormat string required

Returns

ExcelRange
public ExcelRange SetShrinkToFit(bool shrinkToFit = true) #

Sets or clears shrink-to-fit text alignment for every cell in the range.

Parameters

shrinkToFit bool = true optional

Returns

ExcelRange
public ExcelRange SetStrikethrough(bool strikethrough = true) #

Sets or clears strikethrough font style for every cell in the range.

Parameters

strikethrough bool = true optional

Returns

ExcelRange
public ExcelRange SetSubscript() #

Formats every cell in the range as subscript.

Returns

ExcelRange
public ExcelRange SetSuperscript() #

Formats every cell in the range as superscript.

Returns

ExcelRange
public ExcelRange SetTextRotation(int rotation) #

Sets Excel text rotation for every cell in the range.

Parameters

rotation int required

Returns

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

Sets or clears single underline font style for every cell in the range.

Parameters

underline bool = true optional

Returns

ExcelRange
public ExcelRange SetUnderline(ExcelUnderlineStyle underlineStyle) #

Sets the native Excel underline style for every cell in the range.

Parameters

underlineStyle OfficeIMO.Excel.ExcelUnderlineStyle required

Returns

ExcelRange
public ExcelRange SetValues(object?[,] values) #

Writes a rectangular matrix whose dimensions exactly match this range.

Parameters

values object?[,] required

Returns

ExcelRange
public ExcelRange SetVerticalAlignment(ExcelVerticalAlignment alignment) #

Sets the vertical alignment of every cell in the range.

Parameters

alignment OfficeIMO.Excel.ExcelVerticalAlignment required

Returns

ExcelRange
public ExcelRange SetVerticalTextAlignment(ExcelVerticalTextAlignment alignment) #

Sets the native Excel baseline, superscript, or subscript alignment for every cell in the range.

Parameters

alignment OfficeIMO.Excel.ExcelVerticalTextAlignment required

Returns

ExcelRange
public ExcelRange SetWrapText(bool wrapText = true) #

Sets or clears text wrapping for every cell in the range.

Parameters

wrapText bool = true optional

Returns

ExcelRange
public ExcelRange SortByColumn(int columnOffset, bool ascending = true, bool hasHeader = true) #

Sorts the range by a 1-based column offset.

Parameters

columnOffset int required
ascending bool = true optional
hasHeader bool = true optional

Returns

ExcelRange
ToImage 2 overloads
public byte[] ToImage(ExcelImageExportOptions? options = null, CancellationToken cancellationToken = default) #

Renders the range using the encoding in OfficeImageExportOptions.Format.

Parameters

options OfficeIMO.Excel.ExcelImageExportOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

byte[]
public byte[] ToImage(ExcelImageExportOptions? options, out OfficeConversionReport report, CancellationToken cancellationToken = default) #

Renders the range and returns its immutable fidelity report.

Parameters

options OfficeIMO.Excel.ExcelImageExportOptions? required
report OfficeIMO.OfficeConversionReport required
cancellationToken System.Threading.CancellationToken = default optional

Returns

byte[]
public async Task<OfficeConversionResult<byte[]>> ToImageAsync(ExcelImageExportOptions? options = null, CancellationToken cancellationToken = default) #

Renders the range with cancellation and returns the bytes and fidelity report.

Parameters

options OfficeIMO.Excel.ExcelImageExportOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task<OfficeConversionResult<byte[]>>
public ExcelRange TransformTextCase(OfficeTextCase textCase, CultureInfo? culture = null) #

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

Parameters

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

Returns

ExcelRange
public ExcelMutationResult TransposeTo(string destinationTopLeft, ExcelMutationPlanOptions? options = null, CancellationToken cancellationToken = default) #

Copies this range to a destination with rows and columns transposed.

Parameters

destinationTopLeft string required
options OfficeIMO.Excel.ExcelMutationPlanOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public ExcelRange Unmerge() #

Removes merge definitions that overlap the range.

Returns

ExcelRange
public ExcelRangeDataValidationBuilder Validation() #

Adds data validation rules to the range.

Properties

public ExcelSheet Sheet { get; } #

Gets the worksheet that owns the range.

public string Address { get; } #

Gets the A1 range address; areas are separated by spaces.

public int FirstRow { get; } #

Gets the first row in the range (of all areas).

public int FirstColumn { get; } #

Gets the first column in the range.

public int LastRow { get; } #

Gets the last row in the range.

public int LastColumn { get; } #

Gets the last column in the range.

public ExcelCell FirstCell { get; } #

Gets a wrapper for the top-left cell.