ExcelRange
OfficeIMO.Excel
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.
Returned or exposed by 42
- Method ExcelDocument.GetNamedRange
- Method ExcelRange.Clear
- Method ExcelRange.Merge
- Method ExcelRange.SetBaseline
- Method ExcelRange.SetBold
- Method ExcelRange.SetBorder
- Method ExcelRange.SetColor
- Method ExcelRange.SetDiagonalBorder
- Method ExcelRange.SetFillColor
- Method ExcelRange.SetFontFamily
- Method ExcelRange.SetFontSize
- Method ExcelRange.SetGradientFill
- Method ExcelRange.SetHorizontalAlignment
- Method ExcelRange.SetItalic
- Method ExcelRange.SetNumberFormat
- Method ExcelRange.SetShrinkToFit
- Method ExcelRange.SetStrikethrough
- Method ExcelRange.SetSubscript
- Method ExcelRange.SetSuperscript
- Method ExcelRange.SetTextRotation
- Method ExcelRange.SetUnderline
- Method ExcelRange.SetValues
- Method ExcelRange.SetVerticalAlignment
- Method ExcelRange.SetVerticalTextAlignment
- Method ExcelRange.SetWrapText
- Method ExcelRange.SortByColumn
- Method ExcelRange.TransformTextCase
- Method ExcelRange.Unmerge
- Method ExcelRangeDataValidationBuilder.CustomFormula
- Method ExcelRangeDataValidationBuilder.Date
- Method ExcelRangeDataValidationBuilder.Decimal
- Method ExcelRangeDataValidationBuilder.List
- Method ExcelRangeDataValidationBuilder.ListNamedRange
- Method ExcelRangeDataValidationBuilder.ListRange
- Method ExcelRangeDataValidationBuilder.TextLength
- Method ExcelRangeDataValidationBuilder.Time
- Method ExcelRangeDataValidationBuilder.WholeNumber
- Method ExcelSheet.GetNamedRange
- Method ExcelSheet.Range
- Property ExcelSheet.UsedRange
- Method ExcelTable.AsRange
- Method ExcelTable.Column
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.
Returns
ExcelAutoFilterpublic ExcelCell Cell(int rowOffset, int columnOffset) #Gets an editable cell using one-based offsets from this range's top-left cell.
Parameters
- rowOffset int
- columnOffset int
Returns
ExcelCellpublic ExcelRange Clear(ExcelClearOptions options = All) #Clears selected data and metadata from the range.
Parameters
- options OfficeIMO.Excel.ExcelClearOptions = All
Returns
ExcelRangepublic 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
- options OfficeIMO.Excel.ExcelMutationPlanOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
ExcelMutationResultpublic ExcelTable CreateTable(string name, bool hasHeader = true, ExcelTableStyle style = TableStyleMedium2, bool includeAutoFilter = true) #Creates an Excel table over the range.
Parameters
- name string
- hasHeader bool = true
- style OfficeIMO.Excel.ExcelTableStyle = TableStyleMedium2
- includeAutoFilter bool = true
Returns
ExcelTablepublic ExcelRangeVisualInfo CreateVisualSnapshot(ExcelImageExportOptions? options = null) #Creates a format-neutral visual snapshot for this range.
Parameters
- options OfficeIMO.Excel.ExcelImageExportOptions? = null
Returns
ExcelRangeVisualInfopublic ExcelMutationResult Delete(ExcelCellShiftDirection direction, ExcelMutationPlanOptions? options = null, CancellationToken cancellationToken = default) #Transactionally deletes this cell block.
Parameters
- direction OfficeIMO.Excel.ExcelCellShiftDirection
- options OfficeIMO.Excel.ExcelMutationPlanOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
ExcelMutationResultpublic 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
- options OfficeIMO.Excel.ExcelImageExportOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
OfficeImageExportResultpublic ExcelMutationResult Insert(ExcelCellShiftDirection direction, ExcelMutationPlanOptions? options = null, CancellationToken cancellationToken = default) #Transactionally inserts a cell block at this range.
Parameters
- direction OfficeIMO.Excel.ExcelCellShiftDirection
- options OfficeIMO.Excel.ExcelMutationPlanOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
ExcelMutationResultpublic ExcelMutationResult MoveTo(string destinationTopLeft, ExcelMutationPlanOptions? options = null, CancellationToken cancellationToken = default) #Moves this range to a destination top-left cell.
Parameters
- destinationTopLeft string
- options OfficeIMO.Excel.ExcelMutationPlanOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
ExcelMutationResultpublic OfficeConversionReport SaveAsImage(string path, ExcelImageExportOptions? options = null, CancellationToken cancellationToken = default) #Writes the range to a file and returns its fidelity report.
Parameters
- path string
- options OfficeIMO.Excel.ExcelImageExportOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
OfficeConversionReportpublic 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
- options OfficeIMO.Excel.ExcelImageExportOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
OfficeConversionReportpublic 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
- options OfficeIMO.Excel.ExcelImageExportOptions? = null
- cancellationToken System.Threading.CancellationToken = default
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
- options OfficeIMO.Excel.ExcelImageExportOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
Task<OfficeConversionReport>public ExcelRange SetBaseline() #Restores every cell in the range to the normal baseline.
Returns
ExcelRangepublic ExcelRange SetBold(bool bold = true) #Sets or clears bold font style for every cell in the range.
Parameters
- bold bool = true
Returns
ExcelRangepublic 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
- color OfficeIMO.OfficeColor? = null
Returns
ExcelRangepublic 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
- style OfficeIMO.Excel.ExcelBorderStyle
- color OfficeIMO.OfficeColor? = null
Returns
ExcelRangepublic ExcelRange SetColor(OfficeColor color) #Applies a font color to every cell in the range.
Parameters
- color OfficeIMO.OfficeColor
Returns
ExcelRangepublic 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
- color OfficeIMO.OfficeColor? = null
- diagonalUp bool = true
- diagonalDown bool = true
Returns
ExcelRangepublic 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
Returns
ExcelRangepublic ExcelRange SetFontFamily(string fontFamily) #Applies a font family name to every cell in the range.
Parameters
- fontFamily string
Returns
ExcelRangepublic ExcelRange SetFontSize(OfficeLength fontSize) #Applies a positive physical font size to every cell in the range.
Parameters
- fontSize OfficeIMO.OfficeLength
Returns
ExcelRangepublic 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
- toColor OfficeIMO.OfficeColor
- degree double = 0
Returns
ExcelRangepublic ExcelRange SetHorizontalAlignment(ExcelHorizontalAlignment alignment) #Sets the horizontal alignment of every cell in the range.
Parameters
- alignment OfficeIMO.Excel.ExcelHorizontalAlignment
Returns
ExcelRangepublic ExcelRange SetItalic(bool italic = true) #Sets or clears italic font style for every cell in the range.
Parameters
- italic bool = true
Returns
ExcelRangepublic ExcelRange SetNumberFormat(string numberFormat) #Applies a number format to every cell in the range.
Parameters
- numberFormat string
Returns
ExcelRangepublic ExcelRange SetShrinkToFit(bool shrinkToFit = true) #Sets or clears shrink-to-fit text alignment for every cell in the range.
Parameters
- shrinkToFit bool = true
Returns
ExcelRangepublic ExcelRange SetStrikethrough(bool strikethrough = true) #Sets or clears strikethrough font style for every cell in the range.
Parameters
- strikethrough bool = true
Returns
ExcelRangepublic ExcelRange SetSuperscript() #Formats every cell in the range as superscript.
Returns
ExcelRangepublic ExcelRange SetTextRotation(int rotation) #Sets Excel text rotation for every cell in the range.
Parameters
- rotation int
Returns
ExcelRangepublic ExcelRange SetUnderline(bool underline = true) #Sets or clears single underline font style for every cell in the range.
Parameters
- underline bool = true
Returns
ExcelRangepublic ExcelRange SetUnderline(ExcelUnderlineStyle underlineStyle) #Sets the native Excel underline style for every cell in the range.
Parameters
- underlineStyle OfficeIMO.Excel.ExcelUnderlineStyle
Returns
ExcelRangepublic ExcelRange SetValues(object?[,] values) #Writes a rectangular matrix whose dimensions exactly match this range.
Parameters
- values object?[,]
Returns
ExcelRangepublic ExcelRange SetVerticalAlignment(ExcelVerticalAlignment alignment) #Sets the vertical alignment of every cell in the range.
Parameters
- alignment OfficeIMO.Excel.ExcelVerticalAlignment
Returns
ExcelRangepublic ExcelRange SetVerticalTextAlignment(ExcelVerticalTextAlignment alignment) #Sets the native Excel baseline, superscript, or subscript alignment for every cell in the range.
Parameters
- alignment OfficeIMO.Excel.ExcelVerticalTextAlignment
Returns
ExcelRangepublic ExcelRange SetWrapText(bool wrapText = true) #Sets or clears text wrapping for every cell in the range.
Parameters
- wrapText bool = true
Returns
ExcelRangepublic ExcelRange SortByColumn(int columnOffset, bool ascending = true, bool hasHeader = true) #Sorts the range by a 1-based column offset.
Parameters
- columnOffset int
- ascending bool = true
- hasHeader bool = true
Returns
ExcelRangepublic byte[] ToImage(ExcelImageExportOptions? options = null, CancellationToken cancellationToken = default) #Renders the range using the encoding in OfficeImageExportOptions.Format.
Parameters
- options OfficeIMO.Excel.ExcelImageExportOptions? = null
- cancellationToken System.Threading.CancellationToken = default
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?
- report OfficeIMO.OfficeConversionReport
- cancellationToken System.Threading.CancellationToken = default
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
- cancellationToken System.Threading.CancellationToken = default
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
- culture System.Globalization.CultureInfo? = null
Returns
ExcelRangepublic ExcelMutationResult TransposeTo(string destinationTopLeft, ExcelMutationPlanOptions? options = null, CancellationToken cancellationToken = default) #Copies this range to a destination with rows and columns transposed.
Parameters
- destinationTopLeft string
- options OfficeIMO.Excel.ExcelMutationPlanOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
ExcelMutationResultpublic ExcelRangeDataValidationBuilder Validation() #Adds data validation rules to the range.
Inherited Methods
Properties
public string Address { get; } #Gets the A1 range address; areas are separated by spaces.