API Reference
ExcelSheet
Helpers for worksheet cell comments (notes).
Inheritance
- Object
- ExcelSheet
Constructors
public ExcelSheet(ExcelDocument excelDocument, SpreadsheetDocument spreadSheetDocument, Sheet sheet) #Initializes a worksheet from an existing Sheet element.
Parameters
- excelDocument OfficeIMO.Excel.ExcelDocument
- Parent document.
- spreadSheetDocument DocumentFormat.OpenXml.Packaging.SpreadsheetDocument
- Open XML spreadsheet document.
- sheet DocumentFormat.OpenXml.Spreadsheet.Sheet
- Underlying sheet element.
public ExcelSheet(ExcelDocument excelDocument, WorkbookPart workbookpart, SpreadsheetDocument spreadSheetDocument, String name) #Creates a new worksheet and appends it to the workbook.
Parameters
- excelDocument OfficeIMO.Excel.ExcelDocument
- Parent document.
- workbookpart DocumentFormat.OpenXml.Packaging.WorkbookPart
- Workbook part to add the worksheet to.
- spreadSheetDocument DocumentFormat.OpenXml.Packaging.SpreadsheetDocument
- Open XML spreadsheet document.
- name System.String
- Worksheet name.
Methods
public Void AddAutoFilter(String range, Dictionary<UInt32, IEnumerable<String>> filterCriteria = null) #VoidAdds an AutoFilter to the worksheet or table.
Parameters
- range System.String
- The cell range to apply the filter to.
- filterCriteria System.Collections.Generic.Dictionary{System.UInt32,System.Collections.Generic.IEnumerable{System.String}} = null
- Optional filter criteria to apply.
public ExcelChart AddBubbleChartFromRanges(IEnumerable<ExcelChartSeriesRange> seriesRanges, Int32 row, Int32 column, Int32 widthPixels = 640, Int32 heightPixels = 360, String title = null) #ExcelChartAdds a bubble chart using explicit X/Y/size ranges.
Parameters
- seriesRanges System.Collections.Generic.IEnumerable{OfficeIMO.Excel.ExcelChartSeriesRange}
- row System.Int32
- column System.Int32
- widthPixels System.Int32 = 640
- heightPixels System.Int32 = 360
- title System.String = null
public ExcelChart AddChart(ExcelChartData data, Int32 row, Int32 column, Int32 widthPixels = 640, Int32 heightPixels = 360, ExcelChartType type = ColumnClustered, String title = null) #ExcelChartAdds a chart to the worksheet using the provided data. Data is stored on a hidden chart data sheet.
Parameters
- data OfficeIMO.Excel.ExcelChartData
- row System.Int32
- column System.Int32
- widthPixels System.Int32 = 640
- heightPixels System.Int32 = 360
- type OfficeIMO.Excel.ExcelChartType = ColumnClustered
- title System.String = null
public ExcelChart AddChart(ExcelChartDataRange dataRange, Int32 row, Int32 column, Int32 widthPixels = 640, Int32 heightPixels = 360, ExcelChartType type = ColumnClustered, ExcelChartData cachedData = null, String title = null) #ExcelChartAdds a chart to the worksheet using an existing data range.
Parameters
- dataRange OfficeIMO.Excel.ExcelChartDataRange
- row System.Int32
- column System.Int32
- widthPixels System.Int32 = 640
- heightPixels System.Int32 = 360
- type OfficeIMO.Excel.ExcelChartType = ColumnClustered
- cachedData OfficeIMO.Excel.ExcelChartData = null
- title System.String = null
public ExcelChart AddChartFromRange(String dataRangeA1, Int32 row, Int32 column, Int32 widthPixels = 640, Int32 heightPixels = 360, ExcelChartType type = ColumnClustered, Boolean hasHeaders = true, String title = null, Boolean includeCachedData = true) #ExcelChartAdds a chart using an A1 range on this sheet.
Parameters
- dataRangeA1 System.String
- row System.Int32
- column System.Int32
- widthPixels System.Int32 = 640
- heightPixels System.Int32 = 360
- type OfficeIMO.Excel.ExcelChartType = ColumnClustered
- hasHeaders System.Boolean = true
- title System.String = null
- includeCachedData System.Boolean = true
public ExcelChart AddChartFromTable(String tableName, Int32 row, Int32 column, Int32 widthPixels = 640, Int32 heightPixels = 360, ExcelChartType type = ColumnClustered, String title = null, Boolean includeCachedData = true) #ExcelChartAdds a chart from a table name on this sheet.
Parameters
- tableName System.String
- row System.Int32
- column System.Int32
- widthPixels System.Int32 = 640
- heightPixels System.Int32 = 360
- type OfficeIMO.Excel.ExcelChartType = ColumnClustered
- title System.String = null
- includeCachedData System.Boolean = true
public Void AddConditionalColorScale(String range, Color startColor, Color endColor) #VoidAdds a two-color scale conditional format to a range.
Parameters
- range System.String
- A1-style range to format.
- startColor SixLabors.ImageSharp.Color
- Starting color of the scale.
- endColor SixLabors.ImageSharp.Color
- Ending color of the scale.
public Void AddConditionalColorScale(String range, String startColor, String endColor) #VoidAdds a two-color scale conditional format to a range using hex colors.
Parameters
- range System.String
- A1-style range to format.
- startColor System.String
- Starting color in hex (e.g. FF0000).
- endColor System.String
- Ending color in hex.
public Void AddConditionalDataBar(String range, Color color) #VoidAdds a data bar conditional format to a range.
Parameters
- range System.String
- A1-style range to format.
- color SixLabors.ImageSharp.Color
- Bar color.
public Void AddConditionalDataBar(String range, String color) #VoidAdds a data bar conditional format to a range using a hex color.
Parameters
- range System.String
- A1-style range to format.
- color System.String
- Bar color in hex (e.g. FF0000).
public Void AddConditionalIconSet(String range, IconSetValues iconSet, Boolean showValue, Boolean reverseIconOrder) #VoidAdds an icon set conditional format to a range.
Parameters
- range System.String
- A1-style range to format.
- iconSet DocumentFormat.OpenXml.Spreadsheet.IconSetValues
- Icon set type (e.g., ThreeTrafficLights1, ThreeSymbols, FourArrows, FiveRatings).
- showValue System.Boolean
- Whether to display the underlying cell values.
- reverseIconOrder System.Boolean
- Reverse icon order.
public Void AddConditionalIconSet(String range, IconSetValues iconSet, Boolean showValue, Boolean reverseIconOrder, Double[] percentThresholds, Double[] numberThresholds) #VoidAdds an icon set conditional format to a range with optional explicit thresholds. Provide either percentThresholds (0..100) or numberThresholds as absolute values. The number of thresholds must match the icon count for the selected icon set (3/4/5).
Parameters
- range System.String
- iconSet DocumentFormat.OpenXml.Spreadsheet.IconSetValues
- showValue System.Boolean
- reverseIconOrder System.Boolean
- percentThresholds System.Double[]
- numberThresholds System.Double[]
public Void AddConditionalIconSet(String range) #VoidOverload with common defaults for convenience.
Parameters
- range System.String
public Void AddConditionalRule(String range, ConditionalFormattingOperatorValues operator, String formula1, String formula2 = null) #VoidAdds a conditional formatting rule to the specified range.
Parameters
- range System.String
- A1-style range to apply the rule to.
- operator DocumentFormat.OpenXml.Spreadsheet.ConditionalFormattingOperatorValues
- Comparison operator for the rule.
- formula1 System.String
- Primary formula or value.
- formula2 System.String = null
- Optional secondary formula or value.
public Void AddImageAt(Int32 row, Int32 column, Byte[] imageBytes, String contentType = "image/png", Int32 widthPixels = 96, Int32 heightPixels = 32, Int32 offsetXPixels = 0, Int32 offsetYPixels = 0) #VoidAdds an image anchored to the specified cell. The top-left of the image will align to the cell's top-left, with optional pixel offsets. Size is specified in pixels and converted to EMUs.
Parameters
- row System.Int32
- 1-based row index.
- column System.Int32
- 1-based column index.
- imageBytes System.Byte[]
- Image bytes.
- contentType System.String = "image/png"
- Content type, e.g. image/png or image/jpeg.
- widthPixels System.Int32 = 96
- Width in pixels.
- heightPixels System.Int32 = 32
- Height in pixels.
- offsetXPixels System.Int32 = 0
- Optional X offset from cell origin in pixels.
- offsetYPixels System.Int32 = 0
- Optional Y offset from cell origin in pixels.
public Void AddImageFromUrlAt(Int32 row, Int32 column, String url, Int32 widthPixels = 96, Int32 heightPixels = 32, Int32 offsetXPixels = 0, Int32 offsetYPixels = 0) #VoidDownloads an image from URL (with timeout and size limits) and anchors it to the specified cell.
Parameters
- row System.Int32
- 1-based row index where the top edge of the image will be anchored.
- column System.Int32
- 1-based column index where the left edge of the image will be anchored.
- url System.String
- Remote image URL to download. Requests timeout after 5 seconds and must be smaller than 2 MB.
- widthPixels System.Int32 = 96
- Desired image width in pixels. Defaults to 96 px, converted to English Metric Units (EMUs) for OpenXML positioning.
- heightPixels System.Int32 = 32
- Desired image height in pixels. Defaults to 32 px, converted to EMUs.
- offsetXPixels System.Int32 = 0
- Optional horizontal offset in pixels from the cell's left boundary. Positive values move the image right; defaults to 0 px.
- offsetYPixels System.Int32 = 0
- Optional vertical offset in pixels from the cell's top boundary. Positive values move the image down; defaults to 0 px.
public Void AddPivotTable(String sourceRange, String destinationCell, String name = null, IEnumerable<String> rowFields = null, IEnumerable<String> columnFields = null, IEnumerable<String> pageFields = null, IEnumerable<ExcelPivotDataField> dataFields = null, Boolean showRowGrandTotals = true, Boolean showColumnGrandTotals = true, String pivotStyleName = null, ExcelPivotLayout layout = Compact, Nullable<Boolean> dataOnRows = null, Nullable<Boolean> showHeaders = null, Nullable<Boolean> showEmptyRows = null, Nullable<Boolean> showEmptyColumns = null, Nullable<Boolean> showDrill = null) #VoidAdds a basic pivot table based on a source range and places it at a destination cell.
Parameters
- sourceRange System.String
- Source data range (including header row), e.g. "A1:D100".
- destinationCell System.String
- Top-left cell for the pivot table (e.g. "F2").
- name System.String = null
- Optional pivot table name. Defaults to "PivotTable1" style.
- rowFields System.Collections.Generic.IEnumerable{System.String} = null
- Optional row fields (header names).
- columnFields System.Collections.Generic.IEnumerable{System.String} = null
- Optional column fields (header names).
- pageFields System.Collections.Generic.IEnumerable{System.String} = null
- Optional page fields (header names) used as filters.
- dataFields System.Collections.Generic.IEnumerable{OfficeIMO.Excel.ExcelPivotDataField} = null
- Optional data field definitions. Defaults to last column with Sum.
- showRowGrandTotals System.Boolean = true
- Show row grand totals.
- showColumnGrandTotals System.Boolean = true
- Show column grand totals.
- pivotStyleName System.String = null
- Optional pivot table style name.
- layout OfficeIMO.Excel.ExcelPivotLayout = Compact
- Layout mode (Compact, Outline, Tabular).
- dataOnRows System.Nullable{System.Boolean} = null
- Whether to show data fields on rows instead of columns.
- showHeaders System.Nullable{System.Boolean} = null
- Whether to show field headers.
- showEmptyRows System.Nullable{System.Boolean} = null
- Whether to show empty rows.
- showEmptyColumns System.Nullable{System.Boolean} = null
- Whether to show empty columns.
- showDrill System.Nullable{System.Boolean} = null
- Whether to show drill indicators.
public ExcelChart AddScatterChartFromRanges(IEnumerable<ExcelChartSeriesRange> seriesRanges, Int32 row, Int32 column, Int32 widthPixels = 640, Int32 heightPixels = 360, String title = null) #ExcelChartAdds a scatter chart using explicit X/Y ranges.
Parameters
- seriesRanges System.Collections.Generic.IEnumerable{OfficeIMO.Excel.ExcelChartSeriesRange}
- row System.Int32
- column System.Int32
- widthPixels System.Int32 = 640
- heightPixels System.Int32 = 360
- title System.String = null
public Void AddSparklines(String dataRange, String locationRange, SparklineTypeValues type, Boolean displayMarkers = false, Boolean displayHighLow = false, Boolean displayFirstLast = false, Boolean displayNegative = false, Boolean displayAxis = false, String seriesColor = null, String axisColor = null, String negativeColor = null, String markersColor = null, String highColor = null, String lowColor = null, String firstColor = null, String lastColor = null) #VoidAdds sparklines to the worksheet.
Parameters
- dataRange System.String
- A1 range containing the data (e.g., "B2:M2").
- locationRange System.String
- A1 range where sparklines will be placed (e.g., "N2:N2").
- type DocumentFormat.OpenXml.Office2010.Excel.SparklineTypeValues
- Sparkline type.
- displayMarkers System.Boolean = false
- Show markers for each data point.
- displayHighLow System.Boolean = false
- Show high/low markers.
- displayFirstLast System.Boolean = false
- Show first/last markers.
- displayNegative System.Boolean = false
- Show negative markers.
- displayAxis System.Boolean = false
- Show axis.
- seriesColor System.String = null
- Sparkline series color (#RRGGBB or #AARRGGBB).
- axisColor System.String = null
- Axis color (#RRGGBB or #AARRGGBB).
- negativeColor System.String = null
- Negative point color (#RRGGBB or #AARRGGBB).
- markersColor System.String = null
- Markers color (#RRGGBB or #AARRGGBB).
- highColor System.String = null
- High point color (#RRGGBB or #AARRGGBB).
- lowColor System.String = null
- Low point color (#RRGGBB or #AARRGGBB).
- firstColor System.String = null
- First point color (#RRGGBB or #AARRGGBB).
- lastColor System.String = null
- Last point color (#RRGGBB or #AARRGGBB).
public Void AddSparklines(String dataRange, String locationRange, Boolean displayMarkers = false, Boolean displayHighLow = false, Boolean displayFirstLast = false, Boolean displayNegative = false, Boolean displayAxis = false, String seriesColor = null, String axisColor = null, String negativeColor = null, String markersColor = null, String highColor = null, String lowColor = null, String firstColor = null, String lastColor = null) #VoidAdds line sparklines to the worksheet.
Parameters
- dataRange System.String
- A1 range containing the data (e.g., "B2:M2").
- locationRange System.String
- A1 range where sparklines will be placed (e.g., "N2:N2").
- displayMarkers System.Boolean = false
- Show markers for each data point.
- displayHighLow System.Boolean = false
- Show high/low markers.
- displayFirstLast System.Boolean = false
- Show first/last markers.
- displayNegative System.Boolean = false
- Show negative markers.
- displayAxis System.Boolean = false
- Show axis.
- seriesColor System.String = null
- Sparkline series color (#RRGGBB or #AARRGGBB).
- axisColor System.String = null
- Axis color (#RRGGBB or #AARRGGBB).
- negativeColor System.String = null
- Negative point color (#RRGGBB or #AARRGGBB).
- markersColor System.String = null
- Markers color (#RRGGBB or #AARRGGBB).
- highColor System.String = null
- High point color (#RRGGBB or #AARRGGBB).
- lowColor System.String = null
- Low point color (#RRGGBB or #AARRGGBB).
- firstColor System.String = null
- First point color (#RRGGBB or #AARRGGBB).
- lastColor System.String = null
- Last point color (#RRGGBB or #AARRGGBB).
public Void AddTable(String range, Boolean hasHeader, String name, TableStyle style) #VoidAdds an Excel table to the worksheet over the specified range.
Parameters
- range System.String
- Cell range (e.g. "A1:B3") defining the table area.
- hasHeader System.Boolean
- Indicates whether the first row is a header row.
- name System.String
- Name of the table. If empty, a default name is used.
- style OfficeIMO.Excel.TableStyle
- Table style to apply.
Exceptions
ArgumentNullException– Thrown when range is null or empty.ArgumentException– Thrown when range is not in a valid format.InvalidOperationException– Thrown when the specified range overlaps with an existing table.
public Void AddTable(String range, Boolean hasHeader, String name, TableStyle style, Boolean includeAutoFilter, TableNameValidationMode validationMode = Sanitize) #VoidAdds an Excel table to the worksheet over the specified range with optional AutoFilter and name validation behavior.
Parameters
- range System.String
- Cell range (e.g. "A1:B3") defining the table area.
- hasHeader System.Boolean
- Indicates whether the first row is a header row.
- name System.String
- Name of the table. If empty, a default name is used. Examples: "My Table" becomes "My_Table"; "123Report" becomes "_123Report"; spaces and invalid characters are replaced with underscores. If a name already exists in this workbook, a numeric suffix is appended (e.g., "Table", "Table2").
- style OfficeIMO.Excel.TableStyle
- Table style to apply.
- includeAutoFilter System.Boolean
- Whether to include AutoFilter dropdowns in the table headers.
- validationMode OfficeIMO.Excel.TableNameValidationMode = Sanitize
- Controls how invalid table names are handled: Sanitize (default) replaces invalid characters and adjusts the name; Strict throws descriptive exceptions for invalid names.
public Void AutoFilterAdd(String a1Range) #VoidAttaches an AutoFilter to the given A1 range (e.g., "A1:C200").
Parameters
- a1Range System.String
public Void AutoFilterByHeaderBetween(String header, Double minimumInclusive, Double maximumInclusive) #VoidApplies an AutoFilter numeric inclusive range filter to a column resolved by header within the current AutoFilter range.
Parameters
- header System.String
- minimumInclusive System.Double
- maximumInclusive System.Double
public Void AutoFilterByHeaderContains(String header, String containsText) #VoidApplies an AutoFilter text contains filter to a column resolved by header within the current AutoFilter range. Uses wildcard pattern matching ("*text*") via CustomFilters with Equal operator. When the header is missing the operation is skipped.
Parameters
- header System.String
- containsText System.String
public Void AutoFilterByHeaderDoesNotContain(String header, String containsText) #VoidApplies an AutoFilter text does-not-contain filter to a column resolved by header within the current AutoFilter range. Uses wildcard pattern matching ("*text*") via CustomFilters with NotEqual operator.
Parameters
- header System.String
- containsText System.String
public Void AutoFilterByHeaderEndsWith(String header, String endsWithText) #VoidApplies an AutoFilter text ends-with filter to a column resolved by header within the current AutoFilter range. Uses wildcard pattern matching ("*text") via CustomFilters with Equal operator.
Parameters
- header System.String
- endsWithText System.String
public Void AutoFilterByHeaderEquals(String header, IEnumerable<String> values) #VoidApplies an AutoFilter equals filter to a column resolved by header within the current AutoFilter range. Ensures an AutoFilter exists over the sheet's UsedRange when none is present. When the header is missing the operation is skipped.
Parameters
- header System.String
- values System.Collections.Generic.IEnumerable{System.String}
public Void AutoFilterByHeaderGreaterThanOrEqual(String header, Double value) #VoidApplies an AutoFilter numeric greater-than-or-equal filter to a column resolved by header within the current AutoFilter range.
Parameters
- header System.String
- value System.Double
public Void AutoFilterByHeaderLessThanOrEqual(String header, Double value) #VoidApplies an AutoFilter numeric less-than-or-equal filter to a column resolved by header within the current AutoFilter range.
Parameters
- header System.String
- value System.Double
public Void AutoFilterByHeaderNotBetween(String header, Double minimumExclusive, Double maximumExclusive) #VoidApplies an AutoFilter numeric outside-range filter to a column resolved by header within the current AutoFilter range. Values lower than minimumExclusive or higher than maximumExclusive remain visible.
Parameters
- header System.String
- minimumExclusive System.Double
- maximumExclusive System.Double
public Void AutoFilterByHeaderNotEqual(String header, Double value) #VoidApplies an AutoFilter numeric not-equal filter to a column resolved by header within the current AutoFilter range.
Parameters
- header System.String
- value System.Double
public Void AutoFilterByHeadersEquals(params ValueTuple<String, IEnumerable<String>>[] filters) #VoidApplies equals filters for multiple headers at once (AND semantics across columns, OR semantics within a column). Headers that cannot be resolved are ignored.
Parameters
- filters System.ValueTuple{System.String,System.Collections.Generic.IEnumerable{System.String}}[]
public Void AutoFilterByHeaderStartsWith(String header, String startsWithText) #VoidApplies an AutoFilter text starts-with filter to a column resolved by header within the current AutoFilter range. Uses wildcard pattern matching ("text*") via CustomFilters with Equal operator.
Parameters
- header System.String
- startsWithText System.String
public Void AutoFitColumn(Int32 columnIndex) #VoidAuto-fits the width of the specified column based on its contents.
Parameters
- columnIndex System.Int32
- 1-based column index.
public Void AutoFitColumns(Nullable<ExecutionMode> mode = null, CancellationToken ct = null) #VoidAutomatically fits all columns based on their content.
Parameters
- mode System.Nullable{OfficeIMO.Excel.ExecutionMode} = null
- Overrides how the auto-fit work is scheduled across columns.
- ct System.Threading.CancellationToken = null
- Cancels the auto-fit pass while widths are being measured or applied.
public Void AutoFitColumnsExcept(IEnumerable<Int32> columnsToSkip, Nullable<ExecutionMode> mode = null, CancellationToken ct = null) #VoidAutomatically fits all columns except the supplied indexes.
Parameters
- columnsToSkip System.Collections.Generic.IEnumerable{System.Int32}
- 1-based column indexes that should not be resized.
- mode System.Nullable{OfficeIMO.Excel.ExecutionMode} = null
- Overrides how the auto-fit work is scheduled for the remaining columns.
- ct System.Threading.CancellationToken = null
- Cancels the auto-fit pass before it completes.
public Void AutoFitColumnsFor(IEnumerable<Int32> columnIndexes, Nullable<ExecutionMode> mode = null, CancellationToken ct = null) #VoidAutomatically fits the supplied set of column indexes.
Parameters
- columnIndexes System.Collections.Generic.IEnumerable{System.Int32}
- 1-based column indexes that should be resized to fit their content.
- mode System.Nullable{OfficeIMO.Excel.ExecutionMode} = null
- Overrides how the auto-fit work is scheduled across the selected columns.
- ct System.Threading.CancellationToken = null
- Cancels the auto-fit pass for the selected columns.
public Void AutoFitRow(Int32 rowIndex) #VoidAuto-fits the height of the specified row based on its contents.
Parameters
- rowIndex System.Int32
- 1-based row index.
public Void AutoFitRows(Nullable<ExecutionMode> mode = null, CancellationToken ct = null) #VoidAutomatically fits all rows based on their content.
Parameters
- mode System.Nullable{OfficeIMO.Excel.ExecutionMode} = null
- Overrides how the auto-fit work is scheduled across rows.
- ct System.Threading.CancellationToken = null
- Cancels the row auto-fit pass while heights are being calculated or applied.
public NoLockContext BeginNoLock() #NoLockContextBegin a no-lock context where operations bypass locking.
public Void Cell(Int32 row, Int32 column, Object value = null, String formula = null, String numberFormat = null) #VoidSets the value, formula, and number format of a cell in a single operation.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.Object = null
- Optional value to assign.
- formula System.String = null
- Optional formula to apply.
- numberFormat System.String = null
- Optional number format code.
public Void CellAlign(Int32 row, Int32 column, HorizontalAlignmentValues alignment) #VoidApplies a horizontal alignment to a single cell.
Parameters
- row System.Int32
- The 1-based row index of the cell to align.
- column System.Int32
- The 1-based column index of the cell to align.
- alignment DocumentFormat.OpenXml.Spreadsheet.HorizontalAlignmentValues
- The horizontal alignment value to apply.
public Void CellBackground(Int32 row, Int32 column, Color color) #VoidApplies solid background to a single cell. Accepts #RRGGBB or #AARRGGBB.
Parameters
- row System.Int32
- The 1-based row index of the cell to fill.
- column System.Int32
- The 1-based column index of the cell to fill.
- hexColor System.String
- The background color expressed as an ARGB or RGB hex string.
CellBackground(System.Int32 row, System.Int32 column, SixLabors.ImageSharp.Color color) #Applies solid background to a single cell using SixLabors color.
Parameters
- row System.Int32
- The 1-based row index of the cell to fill.
- column System.Int32
- The 1-based column index of the cell to fill.
- color SixLabors.ImageSharp.Color
- The Color to convert to a hex value.
public Void CellBold(Int32 row, Int32 column, Boolean bold = true) #VoidApplies bold font to a single cell.
Parameters
- row System.Int32
- The 1-based row index of the cell to modify.
- column System.Int32
- The 1-based column index of the cell to modify.
- bold System.Boolean = true
- Whether the font should be bold (true) or regular (false).
public Void CellFontColor(Int32 row, Int32 column, String hexColor) #VoidApplies a font color (ARGB hex or #RRGGBB) to a single cell.
Parameters
- row System.Int32
- The 1-based row index of the cell to recolor.
- column System.Int32
- The 1-based column index of the cell to recolor.
- hexColor System.String
- The desired font color expressed as an ARGB or RGB hex string.
public Void CellFormula(Int32 row, Int32 column, String formula) #VoidSets a formula in the specified cell.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- formula System.String
- The formula expression.
public Void CellValue<T>(Int32 row, Int32 column, Nullable<T> value) #VoidSets the specified value into a cell, inferring the data type.
Type Parameters
- T
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.String
- The value to assign.
public Void CellValue(Int32 row, Int32 column, Double value) #VoidSets the specified value into a cell, inferring the data type.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.Double
- The value to assign.
public Void CellValue(Int32 row, Int32 column, Decimal value) #VoidSets the specified value into a cell, inferring the data type.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.Decimal
- The value to assign.
public Void CellValue(Int32 row, Int32 column, DateTime value) #VoidSets the specified value into a cell, inferring the data type.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.DateTime
- The value to assign.
public Void CellValue(Int32 row, Int32 column, DateTimeOffset value) #VoidSets the specified value into a cell, inferring the data type.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.DateTimeOffset
- The value to assign.
public Void CellValue(Int32 row, Int32 column, TimeSpan value) #VoidSets the specified value into a cell, inferring the data type.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.TimeSpan
- The value to assign.
public Void CellValue(Int32 row, Int32 column, UInt32 value) #VoidSets the specified value into a cell, inferring the data type.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.UInt32
- The value to assign.
public Void CellValue(Int32 row, Int32 column, UInt64 value) #VoidSets the specified value into a cell, inferring the data type.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.UInt64
- The value to assign.
public Void CellValue(Int32 row, Int32 column, UInt16 value) #VoidSets the specified value into a cell, inferring the data type.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.UInt16
- The value to assign.
public Void CellValue(Int32 row, Int32 column, Byte value) #VoidSets the specified value into a cell, inferring the data type.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.Byte
- The value to assign.
public Void CellValue(Int32 row, Int32 column, SByte value) #VoidSets the specified value into a cell, inferring the data type.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.SByte
- The value to assign.
public Void CellValue(Int32 row, Int32 column, Boolean value) #VoidSets the specified value into a cell, inferring the data type.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.Boolean
- The value to assign.
public Void CellValue(Int32 row, Int32 column, Object value) #VoidSets the specified value into a cell, inferring the data type.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.Object
- The value to assign.
public Void CellValues(IEnumerable<ValueTuple<Int32, Int32, Object>> cells, Nullable<ExecutionMode> mode = null, CancellationToken ct = null) #VoidWrites multiple cell values efficiently, using parallelization when beneficial.
Parameters
- cells System.Collections.Generic.IEnumerable{System.ValueTuple{System.Int32,System.Int32,System.Object}}
- Collection of cell coordinates and values.
- mode System.Nullable{OfficeIMO.Excel.ExecutionMode} = null
- Optional execution mode override.
- ct System.Threading.CancellationToken = null
- Cancellation token.
public Void CellValuesParallel(IEnumerable<ValueTuple<Int32, Int32, Object>> cells) #VoidObsolete("Use CellValues(..., ExecutionMode.Parallel) instead.")Obsolete. Use CancellationToken) with Parallel instead.
Parameters
- cells System.Collections.Generic.IEnumerable{System.ValueTuple{System.Int32,System.Int32,System.Object}}
- Collection of cell coordinates and values.
CellValue``1(System.Int32 row, System.Int32 column, System.Nullable{``0} value) #Sets the value of a cell using a nullable struct.
Type Parameters
- T
- The value type.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- value System.Nullable{``0}
- The nullable value to assign.
public Void ClearComment(Int32 row, Int32 column) #VoidRemoves a comment from the specified cell (if present).
Parameters
- row System.Int32
- 1-based row index.
- column System.Int32
- 1-based column index.
public Void ClearComment(String a1) #VoidRemoves a comment from the specified A1 cell reference (if present).
Parameters
- a1 System.String
- A1 cell reference (e.g., "B5").
public ColumnStyleByHeaderBuilder ColumnStyleByHeader(String header, Boolean includeHeader = false, ExcelReadOptions options = null) #ColumnStyleByHeaderBuilderReturns a builder for styling a column resolved by header with discoverable methods. When the header cannot be resolved an inert builder is returned so calls become no-ops.
Parameters
- header System.String
- Header text used to resolve the target column after applying any configured normalization.
- includeHeader System.Boolean = false
- True to include the header row when styling; false to begin styling from the first data row.
- options OfficeIMO.Excel.ExcelReadOptions = null
- Read options that control header normalization and other resolution behavior.
Commit() #Persists pending changes on this worksheet to its underlying OpenXml part.
EnsureDefaultStylePrimitives(DocumentFormat.OpenXml.Spreadsheet.Stylesheet arg1) #Ensures required default style primitives exist and their counts are consistent. Excel expects at least 1 Font, 2 Fills (None, Gray125), 1 Border, 1 CellStyleFormat, and 1 CellFormat present.
Parameters
- arg1 DocumentFormat.OpenXml.Spreadsheet.Stylesheet
EnsureValidUniqueTableName(System.String arg1, OfficeIMO.Excel.TableNameValidationMode arg2) #Ensures a valid and unique table name according to OfficeIMO rules. Rules: - Allowed characters: letters, digits, underscore; spaces become underscores. - Names cannot start with a digit; an underscore is prefixed if necessary. - Names are scoped per workbook and checked case-insensitively. - When mode is Strict, throws for invalid input. Examples: - "My Table" ⇒ "My_Table" - "Sales#2025" ⇒ "Sales_2025" - "123Report" ⇒ "_123Report" - If "Table" already exists, next becomes "Table2" ("Table3", ...)
Parameters
- arg1 System.String
- arg2 OfficeIMO.Excel.TableNameValidationMode
EnsureWorksheetElementOrder() #Ensures all worksheet elements are in the correct order according to OpenXML schema. This must be called before saving to prevent validation errors.
ExecuteWithPolicy(System.String opName, System.Int32 itemCount, System.Nullable{OfficeIMO.Excel.ExecutionMode} overrideMode, System.Action sequentialCore, System.Action computeParallel, System.Action applySequential, System.Threading.CancellationToken ct) #Core execution helper that handles a compute/apply split with optional parallelization. Compute runs without locks; only the apply stage is serialized under a document-level lock.
Parameters
- opName System.String
- A short operation name used for diagnostics and policy decisions.
- itemCount System.Int32
- Approximate number of items to process; used to decide parallel vs sequential. This does not have to be exact but should reflect relative workload.
- overrideMode System.Nullable{OfficeIMO.Excel.ExecutionMode}
- Force a specific execution mode (Sequential/Parallel); null to use policy (Automatic).
- sequentialCore System.Action
- Single-threaded path. Used either when policy decides sequential or when compute/apply are not provided.
- computeParallel System.Action
- Compute phase that is safe to run without locks and must not mutate the OpenXML DOM.
- applySequential System.Action
- Apply phase that writes to the DOM. This runs once under a serialized lock.
- ct System.Threading.CancellationToken
- Cancellation token for the compute phase.
public String FindFirst(String text) #StringFinds the first cell text that contains the specified value. Returns the A1 address or null. Searches values rendered as text (shared strings, inline strings, numbers as invariant strings).
Parameters
- text System.String
public Void ForEachColumn(String a1, Action<Int32> action) #VoidIterates over column indices inside an A1 range and invokes action for each column.
Parameters
- a1 System.String
- A1 range without a sheet prefix.
- action System.Action{System.Int32}
- Callback receiving a 1-based column index.
Examples
sheet.ForEachRow("A2:A10", r => sheet.SetInternalLink(r, 1, "'Summary'!A1", "Back"));
public Void ForEachRow(String a1, Action<Int32> action) #VoidIterates over row indices inside an A1 range and invokes action for each row.
Parameters
- a1 System.String
- A1 range without a sheet prefix.
- action System.Action{System.Int32}
- Callback receiving a 1-based row index.
Examples
var bounds = sheet.GetRangeBounds("A2:D20"); // bounds.r1=2, bounds.c1=1, bounds.r2=20, bounds.c2=4
public Void FormatCell(Int32 row, Int32 column, String numberFormat) #VoidApplies a number format to the specified cell.
Parameters
- row System.Int32
- The 1-based row index.
- column System.Int32
- The 1-based column index.
- numberFormat System.String
- The number format code to apply.
public Void Freeze(Int32 topRows = 0, Int32 leftCols = 0) #VoidFreezes panes on the worksheet.
Parameters
- topRows System.Int32 = 0
- Number of rows at the top to freeze.
- leftCols System.Int32 = 0
- Number of columns on the left to freeze.
public IReadOnlyDictionary<String, String> GetAllNamedRanges() #IReadOnlyDictionary<String, String>Returns all defined names visible to this sheet with their A1 ranges.
public ExcelChart GetChart(String name) #ExcelChartReturns a chart by name (non-visual name), or null if not found.
Parameters
- name System.String
public Dictionary<String, Int32> GetHeaderMap(ExcelReadOptions options = null) #Dictionary<String, Int32>Builds or returns a cached case-insensitive map of header name to 1-based column index using the first row of UsedRange. Cache is keyed by UsedRange A1 and NormalizeHeaders option.
Parameters
- options OfficeIMO.Excel.ExcelReadOptions = null
public String GetNamedRange(String name) #StringGets the A1 range for the given defined name, scoped to this sheet when applicable.
Parameters
- name System.String
- Defined name to resolve.
Returns
A1 range (e.g. "A1:B5") or null if not found.
public IReadOnlyList<ExcelPivotTableInfo> GetPivotTables() #IReadOnlyList<ExcelPivotTableInfo>Returns pivot tables defined on this worksheet.
public ValueTuple<Int32, Int32, Int32, Int32> GetRangeBounds(String a1) #ValueTuple<Int32, Int32, Int32, Int32>Parses an A1 range and returns 1-based bounds (r1, c1, r2, c2).
Parameters
- a1 System.String
- A1 range without a sheet prefix (e.g., "A2:D20").
Returns
Tuple of (r1, c1, r2, c2) with normalized bounds.
Exceptions
ArgumentException– Thrown when the input is not a valid A1 range.
public String GetUsedRangeA1() #StringReturns the used range of this worksheet as an A1 string by leveraging the read bridge.
GuessLinkDisplay(System.String arg1) #Parameters
- arg1 System.String
Examples
sheet.SetHyperlinkHost(7, 1, "https://learn.microsoft.com/office/open-xml/"); // displays "learn.microsoft.com"
public Boolean HasComment(Int32 row, Int32 column) #BooleanReturns true when a comment exists for the specified cell.
Parameters
- row System.Int32
- 1-based row index.
- column System.Int32
- 1-based column index.
public Void InsertDataTable(DataTable table, Int32 startRow = 1, Int32 startColumn = 1, Boolean includeHeaders = true, Nullable<ExecutionMode> mode = null, CancellationToken ct = null) #VoidInserts a DataTable into the worksheet starting at the specified cell. Uses the batch CellValues compute/apply model with SharedString and Style planners.
Parameters
- table System.Data.DataTable
- Source DataTable.
- startRow System.Int32 = 1
- 1-based start row.
- startColumn System.Int32 = 1
- 1-based start column.
- includeHeaders System.Boolean = true
- Whether to write column headers.
- mode System.Nullable{OfficeIMO.Excel.ExecutionMode} = null
- Optional execution mode override.
- ct System.Threading.CancellationToken = null
- Cancellation token.
public String InsertDataTableAsTable(DataTable table, Int32 startRow = 1, Int32 startColumn = 1, Boolean includeHeaders = true, String tableName = null, TableStyle style = TableStyleMedium2, Boolean includeAutoFilter = true, Nullable<ExecutionMode> mode = null, CancellationToken ct = null) #StringInserts a DataTable and immediately creates an Excel Table over the written range. Returns the A1-style range of the created table.
Parameters
- table System.Data.DataTable
- startRow System.Int32 = 1
- startColumn System.Int32 = 1
- includeHeaders System.Boolean = true
- tableName System.String = null
- style OfficeIMO.Excel.TableStyle = TableStyleMedium2
- includeAutoFilter System.Boolean = true
- mode System.Nullable{OfficeIMO.Excel.ExecutionMode} = null
- ct System.Threading.CancellationToken = null
public Void InsertObjects<T>(IEnumerable<T> items, Boolean includeHeaders, Int32 startRow, params ValueTuple<String, Func<T, Object>>[] columns) #VoidType Parameters
- T
Parameters
- items IEnumerable<T>
- includeHeaders Boolean = true
- startRow Int32 = 1
InsertObjects``1(System.Collections.Generic.IEnumerable{``0} items, System.Boolean includeHeaders, System.Int32 startRow) #Inserts objects into the worksheet by flattening their properties into columns.
Type Parameters
- T
- Type of objects being inserted.
Parameters
- items System.Collections.Generic.IEnumerable{``0}
- Collection of objects to insert.
- includeHeaders System.Boolean
- Whether to include column headers.
- startRow System.Int32
- 1-based starting row.
InsertObjects``1(System.Collections.Generic.IEnumerable{``0} items, System.ValueTuple{System.String,System.Func{``0,System.Object}}[] columns) #Inserts objects into the worksheet using explicit column selectors (AOT-safe).
Type Parameters
- T
- Type of objects being inserted.
Parameters
- items System.Collections.Generic.IEnumerable{``0}
- Collection of objects to insert.
- columns System.ValueTuple{System.String,System.Func{``0,System.Object}}[]
- Column headers and selectors.
InsertObjects``1(System.Collections.Generic.IEnumerable{``0} items, System.Boolean includeHeaders, System.Int32 startRow, System.ValueTuple{System.String,System.Func{``0,System.Object}}[] columns) #Inserts objects into the worksheet using explicit column selectors (AOT-safe).
Type Parameters
- T
- Type of objects being inserted.
Parameters
- items System.Collections.Generic.IEnumerable{``0}
- Collection of objects to insert.
- includeHeaders System.Boolean
- Whether to include column headers.
- startRow System.Int32
- 1-based starting row.
- columns System.ValueTuple{System.String,System.Func{``0,System.Object}}[]
- Column headers and selectors.
public Void LinkByHeaderToInternalSheets(String header, Int32 rowFrom = 2, Int32 rowTo = -1, Func<String, String> destinationSheetForCellText = null, String targetA1 = "A1", Func<String, String> display = null, Boolean styled = true) #VoidLinks a column identified by header to internal sheets using each cell's text. Defaults to linking to a sheet with the same name as the cell text. When the header is missing the operation is skipped.
Parameters
- header System.String
- Header text of the column to process.
- rowFrom System.Int32 = 2
- First data row (1-based). Defaults to 2 (skip header).
- rowTo System.Int32 = -1
- Last data row (inclusive). When <= 0, uses the bottom of the used range.
- destinationSheetForCellText System.Func{System.String,System.String} = null
- Maps cell text to a destination sheet name; defaults to identity.
- targetA1 System.String = "A1"
- Destination cell on the target sheet (default "A1").
- display System.Func{System.String,System.String} = null
- Optional display selector; defaults to the cell text.
- styled System.Boolean = true
- Apply hyperlink styling (blue + underline).
public Void LinkByHeaderToInternalSheetsInRange(String rangeA1, String header, Func<String, String> destinationSheetForCellText = null, String targetA1 = "A1", Func<String, String> display = null, Boolean styled = true) #VoidLinks a column identified by header within a rectangular A1 range to internal sheets. Uses the first row of the range as the header row and links rows r1+1..r2.
Parameters
- rangeA1 System.String
- A1 range (e.g., "A1:D50"). The first row is treated as the header row.
- header System.String
- Header text to match (case-insensitive).
- destinationSheetForCellText System.Func{System.String,System.String} = null
- Maps cell text to destination sheet name (defaults to identity).
- targetA1 System.String = "A1"
- Destination cell on the target sheet (default "A1").
- display System.Func{System.String,System.String} = null
- Optional display selector; defaults to the cell text.
- styled System.Boolean = true
- Apply hyperlink styling (blue + underline).
public Void LinkByHeaderToInternalSheetsInTable(String tableName, String header, Func<String, String> destinationSheetForCellText = null, String targetA1 = "A1", Func<String, String> display = null, Boolean styled = true) #VoidLinks a column within a table to internal sheets. The table range determines the row bounds.
Parameters
- tableName System.String
- Name of the table (as shown in Excel's Name Manager).
- header System.String
- Header text of the column inside the table.
- destinationSheetForCellText System.Func{System.String,System.String} = null
- Maps cell text to a destination sheet name (defaults to identity).
- targetA1 System.String = "A1"
- Destination cell on the target sheet (default "A1").
- display System.Func{System.String,System.String} = null
- Optional display selector; defaults to the cell text.
- styled System.Boolean = true
- Apply hyperlink styling (blue + underline).
Examples
// Internal: link "Domain" column to same-named sheets, rows 2..used bottom sheet.LinkByHeaderToInternalSheets("Domain"); // External: link "RFC" column to IETF datatracker pages sheet.LinkByHeaderToUrls("RFC", urlForCellText: rfc => $"https://datatracker.ietf.org/doc/html/{rfc}");
public Void LinkByHeaderToUrls(String header, Int32 rowFrom = 2, Int32 rowTo = -1, Func<String, String> urlForCellText = null, Func<String, String> titleForCellText = null, Boolean styled = true) #VoidLinks a column identified by header to external URLs built from each cell's text. When the header is missing the operation is skipped.
Parameters
- header System.String
- Header text of the column to process.
- rowFrom System.Int32 = 2
- First data row (1-based). Defaults to 2 (skip header).
- rowTo System.Int32 = -1
- Last data row (inclusive). When <= 0, uses the bottom of the used range.
- urlForCellText System.Func{System.String,System.String} = null
- Maps cell text to URL.
- titleForCellText System.Func{System.String,System.String} = null
- Optional display selector; when null, a smart display (RFC/host) is used.
- styled System.Boolean = true
- Apply hyperlink styling (blue + underline).
public Void LinkByHeaderToUrlsInRange(String rangeA1, String header, Func<String, String> urlForCellText, Func<String, String> titleForCellText = null, Boolean styled = true) #VoidLinks a column identified by header within a rectangular A1 range to external URLs. Uses the first row of the range as the header row and links rows r1+1..r2.
Parameters
- rangeA1 System.String
- A1 range (e.g., "A1:D50"). The first row is treated as the header row.
- header System.String
- Header text to match (case-insensitive).
- urlForCellText System.Func{System.String,System.String}
- Maps cell text to URL.
- titleForCellText System.Func{System.String,System.String} = null
- Optional display selector; when null, a smart display (RFC/host) is used.
- styled System.Boolean = true
- Apply hyperlink styling (blue + underline).
public Void LinkByHeaderToUrlsInTable(String tableName, String header, Func<String, String> urlForCellText, Func<String, String> titleForCellText = null, Boolean styled = true) #VoidLinks a column within a table to external URLs. The table range determines the row bounds.
Parameters
- tableName System.String
- Name of the table.
- header System.String
- Header text of the column inside the table.
- urlForCellText System.Func{System.String,System.String}
- Maps cell text to URL.
- titleForCellText System.Func{System.String,System.String} = null
- Optional display selector; when null, a smart display (RFC/host) is used.
- styled System.Boolean = true
- Apply hyperlink styling (blue + underline).
public Void LinkCellsToInternalSheets(String a1, Func<String, String> destinationSheetForCellText, String targetA1 = "A1", Func<String, String> display = null, Boolean styled = true) #VoidConverts each non-empty cell in the A1 range into an internal hyperlink. The destination sheet name is computed from the cell's text using destinationSheetForCellText.
Parameters
- a1 System.String
- A1 range to process (e.g., a column of names).
- destinationSheetForCellText System.Func{System.String,System.String}
- Maps the cell text to a destination sheet name.
- targetA1 System.String = "A1"
- Destination cell on the target sheet (default "A1").
- display System.Func{System.String,System.String} = null
- Optional display text selector. Defaults to the cell text.
- styled System.Boolean = true
- When true, applies hyperlink styling (blue + underline).
Examples
sheet.ForEachColumn("A1:E1", c => sheet.CellBold(1, c, true));
Preflight() #Removes empty containers and orphaned references on this worksheet to prevent Excel repairs.
public Void Protect(ExcelSheetProtectionOptions options = null) #VoidApplies worksheet protection using the provided options.
Parameters
- options OfficeIMO.Excel.ExcelSheetProtectionOptions = null
- Protection options (defaults allow selection of locked/unlocked cells).
public Void RefreshHeaderCache(ExcelReadOptions options = null) #VoidForces rebuilding the header map for the current UsedRange and options.
Parameters
- options OfficeIMO.Excel.ExcelReadOptions = null
public Boolean RemoveNamedRange(String name, Boolean save = true) #BooleanRemoves a defined name scoped to this sheet.
Parameters
- name System.String
- Defined name to remove.
- save System.Boolean = true
- When true, saves the workbook after removal.
Returns
True if removed; false if not found.
public Int32 ReplaceAll(String oldText, String newText) #Int32Replaces all occurrences of oldText with newText in string cells. Returns the number of replacements performed.
Parameters
- oldText System.String
- newText System.String
public IEnumerable<Dictionary<String, Object>> Rows(ExcelReadOptions options = null) #IEnumerable<Dictionary<String, Object>>Reads the sheet's used range as a sequence of dictionaries using the first row as headers.
Parameters
- options OfficeIMO.Excel.ExcelReadOptions = null
- Optional read options/presets.
public IEnumerable<Dictionary<String, Object>> Rows(String a1Range, ExcelReadOptions options = null) #IEnumerable<Dictionary<String, Object>>Reads the specified A1 range as a sequence of dictionaries using the first row of the range as headers.
Parameters
- a1Range System.String
- Inclusive A1 range (e.g., "A1:C100").
- options OfficeIMO.Excel.ExcelReadOptions = null
- Optional read options/presets.
public IEnumerable<T> RowsAs<T>(String a1Range, ExcelReadOptions options = null) #IEnumerable<T>Type Parameters
- T
Parameters
- a1Range String
- options ExcelReadOptions = null
RowsAs``1(System.String a1Range, OfficeIMO.Excel.ExcelReadOptions options) #Maps the specified A1 range to a sequence of T using header-to-property mapping.
Parameters
- a1Range System.String
- options OfficeIMO.Excel.ExcelReadOptions
public IEnumerable<RowEdit> RowsObjects(ExcelReadOptions options = null) #IEnumerable<RowEdit>Reads the sheet's used range as editable rows. First row is treated as headers.
Parameters
- options OfficeIMO.Excel.ExcelReadOptions = null
public IEnumerable<RowEdit> RowsObjects(String a1Range, ExcelReadOptions options = null) #IEnumerable<RowEdit>Reads the specified A1 range as editable rows. First row is treated as headers.
Parameters
- a1Range System.String
- options OfficeIMO.Excel.ExcelReadOptions = null
public Void SetByHeader(Int32 rowIndex, String header, Object value, ExcelReadOptions options = null) #VoidSets a cell value in the specified row by resolving the column using the header name. Does nothing when the header cannot be found.
Parameters
- rowIndex System.Int32
- header System.String
- value System.Object
- options OfficeIMO.Excel.ExcelReadOptions = null
public Void SetCellValues(IEnumerable<ValueTuple<Int32, Int32, Object>> cells, Nullable<ExecutionMode> mode = null, CancellationToken ct = null) #VoidObsolete("Use CellValues(...) instead.")Obsolete. Use CancellationToken) instead.
Parameters
- cells System.Collections.Generic.IEnumerable{System.ValueTuple{System.Int32,System.Int32,System.Object}}
- mode System.Nullable{OfficeIMO.Excel.ExecutionMode} = null
- ct System.Threading.CancellationToken = null
public Void SetColumnWidth(Int32 columnIndex, Double width) #VoidSets the width of the specified column.
Parameters
- columnIndex System.Int32
- 1-based column index.
- width System.Double
- The column width.
public Void SetComment(Int32 row, Int32 column, String text, String author = "OfficeIMO", String initials = null) #VoidAdds or replaces a comment on the specified cell.
Parameters
- row System.Int32
- 1-based row index.
- column System.Int32
- 1-based column index.
- text System.String
- Comment text.
- author System.String = "OfficeIMO"
- Author name (optional).
- initials System.String = null
- Author initials (optional).
public Void SetComment(String a1, String text, String author = "OfficeIMO", String initials = null) #VoidAdds or replaces a comment on the specified A1 cell reference.
Parameters
- a1 System.String
- A1 cell reference (e.g., "B5").
- text System.String
- Comment text.
- author System.String = "OfficeIMO"
- Author name (optional).
- initials System.String = null
- Author initials (optional).
public Void SetGridlinesVisible(Boolean visible) #VoidShows or hides gridlines on the current sheet (view-level setting).
Parameters
- visible System.Boolean
public Void SetHyperlink(Int32 row, Int32 column, String url, String display = null, Boolean style = true) #VoidSets an external hyperlink on a single cell. If display is null or empty, the URL is shown.
Parameters
- row System.Int32
- 1-based row index.
- column System.Int32
- 1-based column index.
- url System.String
- Target URL.
- display System.String = null
- Optional display text. When null/empty, the URL is displayed.
- style System.Boolean = true
- When true, applies hyperlink styling (blue + underline).
public Void SetHyperlink(String a1, String url, String display = null, Boolean style = true) #VoidSets an external hyperlink using an A1 reference (e.g., "B5").
Parameters
- a1 System.String
- A1 cell reference without a sheet prefix.
- url System.String
- Target URL.
- display System.String = null
- Optional display text. When null/empty, the URL is displayed.
- style System.Boolean = true
- When true, applies hyperlink styling (blue + underline).
Examples
sheet.SetHyperlink(2, 1, "https://example.org", display: "Example", style: true);
public Void SetHyperlinkHost(Int32 row, Int32 column, String url, Boolean style = true) #VoidCreates an external hyperlink showing only the host (e.g., example.org) as display text.
Parameters
- row System.Int32
- 1-based row index.
- column System.Int32
- 1-based column index.
- url System.String
- Target URL.
- style System.Boolean = true
- When true, applies hyperlink styling (blue + underline).
Examples
sheet.SetHyperlinkSmart(5, 1, "https://datatracker.ietf.org/doc/html/rfc7208"); // displays "RFC 7208" sheet.SetHyperlinkSmart(6, 1, "https://example.org/path", title: "Spec"); // displays "Spec"
public Void SetHyperlinkSmart(Int32 row, Int32 column, String url, String title = null, Boolean style = true) #VoidCreates an external hyperlink using a smart display strategy: prefer title, then an RFC label (e.g., "RFC 7208") when detected, otherwise the URL host.
Parameters
- row System.Int32
- 1-based row index.
- column System.Int32
- 1-based column index.
- url System.String
- Target URL.
- title System.String = null
- Optional preferred display text.
- style System.Boolean = true
- When true, applies hyperlink styling (blue + underline).
Examples
// Given a summary table where column A contains sheet names, link each cell to its sheet sheet.LinkCellsToInternalSheets("A2:A51", text => text, targetA1: "A1", styled: true);
public Void SetInternalLink(Int32 row, Int32 column, String location, String display = null, Boolean style = true) #VoidSets an internal hyperlink (location in this workbook), e.g., "'Sheet1'!A1".
Parameters
- row System.Int32
- 1-based row index.
- column System.Int32
- 1-based column index.
- location System.String
- Target location inside the workbook (e.g., "'Summary'!A1").
- display System.String = null
- Optional display text. When null/empty, location is displayed.
- style System.Boolean = true
- When true, applies hyperlink styling (blue + underline).
Examples
sheet.SetHyperlink("B5", "https://contoso.com");
public Void SetInternalLink(Int32 row, Int32 column, ExcelSheet target, String a1, String display = null, Boolean style = true) #VoidSets an internal hyperlink to a target sheet and A1 location using safe quoting rules.
Parameters
- row System.Int32
- 1-based row index.
- column System.Int32
- 1-based column index.
- target OfficeIMO.Excel.ExcelSheet
- Target sheet.
- a1 System.String
- A1 reference on the target sheet.
- display System.String = null
- Optional display text. When null/empty, the location is displayed.
- style System.Boolean = true
- When true, applies hyperlink styling (blue + underline).
Examples
// Link A2 to the top of Summary sheet sheet.SetInternalLink(2, 1, "'Summary'!A1", display: "Summary", style: true);
public Void SetMargins(Double left, Double right, Double top, Double bottom, Double header = 0.3, Double footer = 0.3) #VoidSets page margins in inches.
Parameters
- left System.Double
- right System.Double
- top System.Double
- bottom System.Double
- header System.Double = 0.3
- footer System.Double = 0.3
public Void SetMarginsPreset(ExcelMarginPreset preset) #VoidApplies a preset set of margins.
Parameters
- preset OfficeIMO.Excel.ExcelMarginPreset
public Void SetNamedRange(String name, String range, Boolean save = true, Boolean hidden = false) #VoidCreates or updates a named range in the workbook, scoped to this sheet.
Parameters
- name System.String
- Defined name to create or update.
- range System.String
- A1 range (e.g. "A1:B5").
- save System.Boolean = true
- When true, saves the workbook after the change.
- hidden System.Boolean = false
- When true, marks the defined name as hidden.
public Void SetNamedRange(String name, String range, Boolean save, Boolean hidden, NameValidationMode validationMode) #VoidCreates or updates a named range in the workbook, scoped to this sheet, with validation control.
Parameters
- name System.String
- Defined name to create or update.
- range System.String
- A1 range (e.g. "A1:B5").
- save System.Boolean
- When true, saves the workbook after the change.
- hidden System.Boolean
- When true, marks the defined name as hidden.
- validationMode OfficeIMO.Excel.NameValidationMode
- Controls how the name and range are validated: Sanitize (default) clamps/adjusts; Strict throws on invalid input.
public Void SetOrientation(ExcelPageOrientation orientation) #VoidSets page orientation (Portrait or Landscape) on the sheet's PageSetup.
Parameters
- orientation OfficeIMO.Excel.ExcelPageOrientation
public Void SetPageSetup(Nullable<UInt32> fitToWidth = null, Nullable<UInt32> fitToHeight = null, Nullable<UInt32> scale = null) #VoidConfigures basic print/page setup for the sheet.
Parameters
- fitToWidth System.Nullable{System.UInt32} = null
- Number of pages to fit horizontally (1 = fit to one page).
- fitToHeight System.Nullable{System.UInt32} = null
- Number of pages to fit vertically (0 = unlimited).
- scale System.Nullable{System.UInt32} = null
- Manual scale (10-400). Ignored if FitToWidth/Height are specified.
public Void SetTableTotals(String range, Dictionary<String, TotalsRowFunctionValues> byHeader) #VoidEnables a totals row for the table covering range and assigns per-column functions by header name. Supported functions are those in TotalsRowFunctionValues (Sum, Average, Count, Min, Max, etc.).
Parameters
- range System.String
- Address of the table range (for example, "A1:D10") whose totals row should be displayed.
- byHeader System.Collections.Generic.Dictionary{System.String,DocumentFormat.OpenXml.Spreadsheet.TotalsRowFunctionValues}
- Mapping of table header names to the totals function that should be applied for each column.
public Void SortUsedRangeByHeader(String header, Boolean ascending = true) #VoidSorts the sheet's UsedRange rows in-place (excluding header) by the column resolved via header. Values-only: rewrites cell values; formulas and styles are not preserved. When the header cannot be resolved the sort is skipped.
Parameters
- header System.String
- ascending System.Boolean = true
public Void SortUsedRangeByHeaders(params ValueTuple<String, Boolean>[] keys) #VoidSorts the sheet's UsedRange rows in-place by multiple headers in the given order (excluding header row). Values-only: rewrites cell values; formulas and styles are not preserved. Missing headers are ignored and when no valid headers remain the sort is skipped.
Parameters
- keys System.ValueTuple{System.String,System.Boolean}[]
public Boolean TryGetCellText(Int32 row, Int32 column, out String text) #BooleanTries to read the display text of a cell at the given position. Returns false if the cell is blank or out of bounds.
Parameters
- row System.Int32
- The 1-based row index of the cell to inspect.
- column System.Int32
- The 1-based column index of the cell to inspect.
- text System.String@
- When this method returns, contains the extracted cell text if successful; otherwise, an empty string.
Returns
true if text was read successfully; otherwise, false.
public Boolean TryGetColumnIndexByHeader(String header, out Int32 columnIndex, ExcelReadOptions options = null) #BooleanTries to resolve a 1-based column index for a given header. Returns false without throwing when the header cannot be found.
Parameters
- header System.String
- columnIndex System.Int32@
- options OfficeIMO.Excel.ExcelReadOptions = null
public Boolean TryLinkByHeaderToInternalSheets(String header, Int32 rowFrom = 2, Int32 rowTo = -1, Func<String, String> destinationSheetForCellText = null, String targetA1 = "A1", Func<String, String> display = null, Boolean styled = true) #BooleanNon-throwing variant of Boolean). Returns false when the header cannot be found or inputs are invalid.
Parameters
- header System.String
- rowFrom System.Int32 = 2
- rowTo System.Int32 = -1
- destinationSheetForCellText System.Func{System.String,System.String} = null
- targetA1 System.String = "A1"
- display System.Func{System.String,System.String} = null
- styled System.Boolean = true
public Boolean TryLinkByHeaderToInternalSheetsInRange(String rangeA1, String header, String targetA1 = "A1", Func<String, String> destinationSheetForCellText = null, Func<String, String> display = null, Boolean styled = true) #BooleanNon-throwing variant of Boolean). Returns false when the range cannot be parsed or the header is missing.
Parameters
- rangeA1 System.String
- header System.String
- targetA1 System.String = "A1"
- destinationSheetForCellText System.Func{System.String,System.String} = null
- display System.Func{System.String,System.String} = null
- styled System.Boolean = true
public Boolean TryLinkByHeaderToInternalSheetsInTable(String tableName, String header, Func<String, String> destinationSheetForCellText = null, String targetA1 = "A1", Func<String, String> display = null, Boolean styled = true) #BooleanNon-throwing variant of Boolean). Returns false when the table or header cannot be found.
Parameters
- tableName System.String
- header System.String
- destinationSheetForCellText System.Func{System.String,System.String} = null
- targetA1 System.String = "A1"
- display System.Func{System.String,System.String} = null
- styled System.Boolean = true
public Boolean TryLinkByHeaderToUrls(String header, Int32 rowFrom = 2, Int32 rowTo = -1, Func<String, String> urlForCellText = null, Func<String, String> titleForCellText = null, Boolean styled = true) #BooleanNon-throwing variant of Boolean). Returns false when the header cannot be found or inputs are invalid.
Parameters
- header System.String
- rowFrom System.Int32 = 2
- rowTo System.Int32 = -1
- urlForCellText System.Func{System.String,System.String} = null
- titleForCellText System.Func{System.String,System.String} = null
- styled System.Boolean = true
public Boolean TryLinkByHeaderToUrlsInRange(String rangeA1, String header, Func<String, String> urlForCellText, Func<String, String> titleForCellText = null, Boolean styled = true) #BooleanNon-throwing variant of Boolean). Returns false when the range cannot be parsed or the header is missing.
Parameters
- rangeA1 System.String
- header System.String
- urlForCellText System.Func{System.String,System.String}
- titleForCellText System.Func{System.String,System.String} = null
- styled System.Boolean = true
public Boolean TryLinkByHeaderToUrlsInTable(String tableName, String header, Func<String, String> urlForCellText, Func<String, String> titleForCellText = null, Boolean styled = true) #BooleanNon-throwing variant of Boolean). Returns false when the table or header cannot be found.
Parameters
- tableName System.String
- header System.String
- urlForCellText System.Func{System.String,System.String}
- titleForCellText System.Func{System.String,System.String} = null
- styled System.Boolean = true
UpdateSheetDimension() #Updates the SheetDimension element to reflect the current used range. Helps avoid rare "dimension" repair messages in Excel when generating sheets programmatically.
public Void ValidationCustomFormula(String a1Range, String formula, Boolean allowBlank = true, String errorTitle = null, String errorMessage = null) #VoidApplies a custom formula validation to the specified A1 range.
Parameters
- a1Range System.String
- formula System.String
- allowBlank System.Boolean = true
- errorTitle System.String = null
- errorMessage System.String = null
public Void ValidationDate(String a1Range, DataValidationOperatorValues operator, DateTime formula1, Nullable<DateTime> formula2 = null, Boolean allowBlank = true, String errorTitle = null, String errorMessage = null) #VoidApplies a date validation to the specified A1 range.
Parameters
- a1Range System.String
- operator DocumentFormat.OpenXml.Spreadsheet.DataValidationOperatorValues
- formula1 System.DateTime
- formula2 System.Nullable{System.DateTime} = null
- allowBlank System.Boolean = true
- errorTitle System.String = null
- errorMessage System.String = null
public Void ValidationDecimal(String a1Range, DataValidationOperatorValues operator, Double formula1, Nullable<Double> formula2 = null, Boolean allowBlank = true, String errorTitle = null, String errorMessage = null) #VoidApplies a decimal number validation to the specified A1 range.
Parameters
- a1Range System.String
- operator DocumentFormat.OpenXml.Spreadsheet.DataValidationOperatorValues
- formula1 System.Double
- formula2 System.Nullable{System.Double} = null
- allowBlank System.Boolean = true
- errorTitle System.String = null
- errorMessage System.String = null
public Void ValidationList(String a1Range, IEnumerable<String> items, Boolean allowBlank = true) #VoidApplies a list validation to the specified A1 range using explicit items.
Parameters
- a1Range System.String
- items System.Collections.Generic.IEnumerable{System.String}
- allowBlank System.Boolean = true
public Void ValidationListNamedRange(String a1Range, String namedRange, Boolean allowBlank = true) #VoidApplies a list validation to the specified A1 range using a workbook or sheet-local named range.
Parameters
- a1Range System.String
- namedRange System.String
- allowBlank System.Boolean = true
public Void ValidationListRange(String a1Range, String sourceA1Range, String sourceSheetName = null, Boolean allowBlank = true) #VoidApplies a list validation to the specified A1 range using a referenced worksheet range. When sourceSheetName is omitted, the current worksheet is used.
Parameters
- a1Range System.String
- sourceA1Range System.String
- sourceSheetName System.String = null
- allowBlank System.Boolean = true
public Void ValidationTextLength(String a1Range, DataValidationOperatorValues operator, Int32 formula1, Nullable<Int32> formula2 = null, Boolean allowBlank = true, String errorTitle = null, String errorMessage = null) #VoidApplies a text length validation to the specified A1 range.
Parameters
- a1Range System.String
- operator DocumentFormat.OpenXml.Spreadsheet.DataValidationOperatorValues
- formula1 System.Int32
- formula2 System.Nullable{System.Int32} = null
- allowBlank System.Boolean = true
- errorTitle System.String = null
- errorMessage System.String = null
public Void ValidationTime(String a1Range, DataValidationOperatorValues operator, TimeSpan formula1, Nullable<TimeSpan> formula2 = null, Boolean allowBlank = true, String errorTitle = null, String errorMessage = null) #VoidApplies a time validation to the specified A1 range.
Parameters
- a1Range System.String
- operator DocumentFormat.OpenXml.Spreadsheet.DataValidationOperatorValues
- formula1 System.TimeSpan
- formula2 System.Nullable{System.TimeSpan} = null
- allowBlank System.Boolean = true
- errorTitle System.String = null
- errorMessage System.String = null
public Void ValidationWholeNumber(String a1Range, DataValidationOperatorValues operator, Int32 formula1, Nullable<Int32> formula2 = null, Boolean allowBlank = true, String errorTitle = null, String errorMessage = null) #VoidApplies a whole number validation to the specified A1 range.
Parameters
- a1Range System.String
- operator DocumentFormat.OpenXml.Spreadsheet.DataValidationOperatorValues
- formula1 System.Int32
- formula2 System.Nullable{System.Int32} = null
- allowBlank System.Boolean = true
- errorTitle System.String = null
- errorMessage System.String = null
public Void WrapCells(Int32 fromRow, Int32 toRow, Int32 column) #VoidEnables WrapText for every cell in a column within a given row range.
Parameters
- fromRow System.Int32
- The first 1-based row index in the range.
- toRow System.Int32
- The last 1-based row index in the range.
- column System.Int32
- The 1-based column index whose cells should wrap.
public Void WrapCells(Int32 fromRow, Int32 toRow, Int32 column, Double targetColumnWidth) #VoidEnables WrapText for the specified column and pins the target column width (in Excel character units). Useful when mixed with auto-fit operations so wrapped columns keep a predictable width.
Parameters
- fromRow System.Int32
- The first 1-based row index in the range.
- toRow System.Int32
- The last 1-based row index in the range.
- column System.Int32
- The 1-based column index whose cells should wrap.
- targetColumnWidth System.Double
- The column width, in Excel character units, to enforce when wrapping.
public ExcelChartDataRange WriteChartData(ExcelChartData data, Int32 startRow = 1, Int32 startColumn = 1, String categoryHeader = null, Boolean includeHeaderRow = true, Boolean numericCategories = false) #ExcelChartDataRangeWrites chart data into the worksheet and returns the corresponding data range.
Parameters
- data OfficeIMO.Excel.ExcelChartData
- startRow System.Int32 = 1
- startColumn System.Int32 = 1
- categoryHeader System.String = null
- includeHeaderRow System.Boolean = true
- numericCategories System.Boolean = false
Inherited Methods
public override Boolean Equals(Object obj) #BooleanParameters
- obj Object
Properties
public IEnumerable<ExcelChart> Charts { get; } #Enumerates charts on the worksheet.
public String Name { get; set; } #Gets or sets the worksheet name.
public ExecutionPolicy ExecutionOverride { get; set; } #Override execution policy for this sheet. Null = inherit from document.
EffectiveExecution #Gets the effective execution policy for this sheet.
public Boolean IsProtected { get; } #Gets whether the worksheet is protected.
public String UsedRangeA1 { get; } #Returns the used range A1 address for this sheet. Alias property for API ergonomics.