OpenXmlExcelWorker
Реализует: IExcelWorker, IDisposable
Конструкторы
public OpenXmlExcelWorker(Stream stream, bool createNew)
openXmlExcelWorker = OpenXmlExcelWorker(stream, createNew)
Initializes a new instance of the OpenXmlExcelWorker.
- stream
- The target stream.
- createNew
- Create a new workbook if ; otherwise open existing XLSX from .
Методы
public IExcelWorker AddAreaChart(string name, string dataRange, int anchorCol, int anchorRow, int width, int height)
result = openXmlExcelWorker.AddAreaChart(name, dataRange, anchorCol, anchorRow, width, height)
Adds an area chart to the current sheet.
- name
- Chart title.
- dataRange
- Data range in A1 notation (e.g., "A1:B100").
- anchorCol
- Column where chart is anchored (0-based).
- anchorRow
- Row where chart is anchored (0-based).
- width
- Chart width in pixels.
- height
- Chart height in pixels.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker AddBarChart(string name, string dataRange, int anchorCol, int anchorRow, int width, int height)
result = openXmlExcelWorker.AddBarChart(name, dataRange, anchorCol, anchorRow, width, height)
Adds a bar/column chart to the current sheet.
- name
- Chart title.
- dataRange
- Data range in A1 notation (e.g., "A1:B100").
- anchorCol
- Column where chart is anchored (0-based).
- anchorRow
- Row where chart is anchored (0-based).
- width
- Chart width in pixels.
- height
- Chart height in pixels.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker AddBubbleChart(string name, string dataRange, int xCol, int yCol, int sizeCol, int anchorCol, int anchorRow, int width, int height)
result = openXmlExcelWorker.AddBubbleChart(name, dataRange, xCol, yCol, sizeCol, anchorCol, anchorRow, width, height)
Adds a bubble chart to the current sheet.
- name
- Chart title.
- dataRange
- Data range in A1 notation (e.g., "A1:C100") with X, Y, and size columns.
- xCol
- Column index for X-axis values (0-based).
- yCol
- Column index for Y-axis values (0-based).
- sizeCol
- Column index for bubble size values (0-based).
- anchorCol
- Column where chart is anchored (0-based).
- anchorRow
- Row where chart is anchored (0-based).
- width
- Chart width in pixels.
- height
- Chart height in pixels.
Возвращает: The current IExcelWorker instance for method chaining.
private uint AddDifferentialFormat(ExcelConditionalFormat fmt)
result = openXmlExcelWorker.AddDifferentialFormat(fmt)
Builds a differential format (dxf) for the given ExcelConditionalFormat, registers it in the stylesheet's DifferentialFormats, and returns its zero-based index for a conditional formatting rule to reference via FormatId.
public IExcelWorker AddDoughnutChart(string name, string dataRange, int anchorCol, int anchorRow, int width, int height)
result = openXmlExcelWorker.AddDoughnutChart(name, dataRange, anchorCol, anchorRow, width, height)
Adds a doughnut chart to the current sheet.
- name
- Chart title.
- dataRange
- Data range in A1 notation (e.g., "A1:B100").
- anchorCol
- Column where chart is anchored (0-based).
- anchorRow
- Row where chart is anchored (0-based).
- width
- Chart width in pixels.
- height
- Chart height in pixels.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker AddLineChart(string name, string dataRange, int xCol, int yCol, int anchorCol, int anchorRow, int width, int height)
result = openXmlExcelWorker.AddLineChart(name, dataRange, xCol, yCol, anchorCol, anchorRow, width, height)
Adds a line chart to the current sheet.
- name
- Chart title.
- dataRange
- Data range in A1 notation (e.g., "A1:B100").
- xCol
- Column index for X-axis values (0-based).
- yCol
- Column index for Y-axis values (0-based).
- anchorCol
- Column where chart is anchored (0-based).
- anchorRow
- Row where chart is anchored (0-based).
- width
- Chart width in pixels.
- height
- Chart height in pixels.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker AddPieChart(string name, string dataRange, int anchorCol, int anchorRow, int width, int height, IEnumerable<string> colors)
result = openXmlExcelWorker.AddPieChart(name, dataRange, anchorCol, anchorRow, width, height, colors)
Adds a pie chart whose slices are explicitly coloured, instead of using Office's automatic per-slice palette.
- name
- Chart title.
- dataRange
- Data range in A1 notation (e.g., "A1:B100").
- anchorCol
- Column where chart is anchored (0-based).
- anchorRow
- Row where chart is anchored (0-based).
- width
- Chart width in pixels.
- height
- Chart height in pixels.
- colors
- Per-slice colors (hex code or name) by slice index; the i-th color fills the i-th slice. Slices beyond the supplied colors (or whose color is empty) keep Office's automatic color.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker AddPieChart(string name, string dataRange, int anchorCol, int anchorRow, int width, int height)
result = openXmlExcelWorker.AddPieChart(name, dataRange, anchorCol, anchorRow, width, height)
Adds a pie chart to the current sheet.
- name
- Chart title.
- dataRange
- Data range in A1 notation (e.g., "A1:B100").
- anchorCol
- Column where chart is anchored (0-based).
- anchorRow
- Row where chart is anchored (0-based).
- width
- Chart width in pixels.
- height
- Chart height in pixels.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker AddRadarChart(string name, string dataRange, int anchorCol, int anchorRow, int width, int height)
result = openXmlExcelWorker.AddRadarChart(name, dataRange, anchorCol, anchorRow, width, height)
Adds a radar (spider) chart to the current sheet.
- name
- Chart title.
- dataRange
- Data range in A1 notation (e.g., "A1:B100").
- anchorCol
- Column where chart is anchored (0-based).
- anchorRow
- Row where chart is anchored (0-based).
- width
- Chart width in pixels.
- height
- Chart height in pixels.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker AddScatterChart(string name, string dataRange, int xCol, int yCol, int anchorCol, int anchorRow, int width, int height)
result = openXmlExcelWorker.AddScatterChart(name, dataRange, xCol, yCol, anchorCol, anchorRow, width, height)
Adds a scatter (XY) chart to the current sheet.
- name
- Chart title.
- dataRange
- Data range in A1 notation (e.g., "A1:B100").
- xCol
- Column index for X-axis values (0-based).
- yCol
- Column index for Y-axis values (0-based).
- anchorCol
- Column where chart is anchored (0-based).
- anchorRow
- Row where chart is anchored (0-based).
- width
- Chart width in pixels.
- height
- Chart height in pixels.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker AddSheet()
result = openXmlExcelWorker.AddSheet()
Adds a new sheet to the workbook.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker AddStockChart(string name, string dataRange, int anchorCol, int anchorRow, int width, int height)
result = openXmlExcelWorker.AddStockChart(name, dataRange, anchorCol, anchorRow, width, height)
Adds a stock (OHLC) chart to the current sheet.
- name
- Chart title.
- dataRange
- Data range in A1 notation with Open, High, Low, Close columns.
- anchorCol
- Column where chart is anchored (0-based).
- anchorRow
- Row where chart is anchored (0-based).
- width
- Chart width in pixels.
- height
- Chart height in pixels.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker AutoFitColumn(int col)
result = openXmlExcelWorker.AutoFitColumn(col)
Auto-fits the column width based on content.
- col
- The column index (0-based).
Возвращает: The current IExcelWorker instance for method chaining.
public bool ContainsSheet(string name)
result = openXmlExcelWorker.ContainsSheet(name)
Checks if a sheet with the specified name exists in the workbook.
- name
- The name of the sheet to check.
Возвращает: true if the sheet exists; otherwise, false.
public IExcelWorker DeleteSheet(string name)
result = openXmlExcelWorker.DeleteSheet(name)
Deletes a sheet by name.
- name
- The name of the sheet to delete.
Возвращает: The current IExcelWorker instance for method chaining.
public void Dispose()
openXmlExcelWorker.Dispose()
Disposes of items in the pool that implement IDisposable.
public IExcelWorker FreezeCols(int count)
result = openXmlExcelWorker.FreezeCols(count)
Freezes the specified number of left columns.
- count
- The number of columns to freeze.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker FreezeRows(int count)
result = openXmlExcelWorker.FreezeRows(count)
Freezes the specified number of top rows.
- count
- The number of rows to freeze.
Возвращает: The current IExcelWorker instance for method chaining.
public T GetCell<T>(int col, int row)
result = openXmlExcelWorker.GetCell(col, row)
Gets the value of a cell at the specified column and row.
- col
- The column index (0-based).
- row
- The row index (0-based).
Возвращает: The value of the cell cast to type .
public int GetColumnsCount()
result = openXmlExcelWorker.GetColumnsCount()
Gets the total number of columns in the current sheet.
Возвращает: The number of columns.
public int GetRowsCount()
result = openXmlExcelWorker.GetRowsCount()
Gets the total number of rows in the current sheet.
Возвращает: The number of rows.
public IEnumerable<string> GetSheetNames()
result = openXmlExcelWorker.GetSheetNames()
Gets the names of all sheets in the workbook.
Возвращает: An enumerable of sheet names.
private static void InsertConditionalFormatting(Worksheet worksheet, ConditionalFormatting conditionalFormatting)
OpenXmlExcelWorker.InsertConditionalFormatting(worksheet, conditionalFormatting)
Inserts a conditional formatting block right after the sheet data (the schema requires it to follow SheetData), appending it if no sheet data exists yet.
public IExcelWorker MergeCells(int startCol, int startRow, int endCol, int endRow)
result = openXmlExcelWorker.MergeCells(startCol, startRow, endCol, endRow)
Merges cells in the specified range.
- startCol
- The starting column index (0-based).
- startRow
- The starting row index (0-based).
- endCol
- The ending column index (0-based).
- endRow
- The ending row index (0-based).
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker RenameSheet(string name)
result = openXmlExcelWorker.RenameSheet(name)
Renames the current sheet to the specified name.
- name
- The new name for the sheet.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker SetCellColor(int col, int row, string bgColor, string fgColor)
result = openXmlExcelWorker.SetCellColor(col, row, bgColor, fgColor)
Sets the colors of a specific cell.
- col
- The column index (0-based).
- row
- The row index (0-based).
- bgColor
- The background color (e.g., hex code or name).
- fgColor
- The foreground (text) color. If null, default is used.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker SetCellColor(int col, int row, string bgColor, ExcelFillPattern pattern, string patternColor, string fgColor)
result = openXmlExcelWorker.SetCellColor(col, row, bgColor, pattern, patternColor, fgColor)
Sets the fill of a specific cell with an explicit pattern. Solid fills with ; any other pattern draws lines/dots over a background.
- col
- The column index (0-based).
- row
- The row index (0-based).
- bgColor
- The fill / background color (hex code or name).
- pattern
- The fill pattern.
- patternColor
- Pattern (lines/dots) color for a non-solid pattern. Defaults to black when empty. Ignored for Solid.
- fgColor
- The foreground (text) color. If null, default is used.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker SetCellFormat(int col, int row, string format)
result = openXmlExcelWorker.SetCellFormat(col, row, format)
Sets the format of a specific cell.
- col
- The column index (0-based).
- row
- The row index (0-based).
- format
- The format string to apply.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker SetCell<T>(int col, int row, T value)
result = openXmlExcelWorker.SetCell(col, row, value)
Sets the value of a cell at the specified column and row.
- col
- The column index (0-based).
- row
- The row index (0-based).
- value
- The value to set in the cell.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker SetColorScale(int col, int startRow, string minColor, string midColor, string maxColor)
result = openXmlExcelWorker.SetColorScale(col, startRow, minColor, midColor, maxColor)
Sets a 3-color scale conditional formatting for a column (gradient from min to mid to max).
- col
- The column index (0-based).
- startRow
- The starting row for the formatting range (0-based, typically 1 to skip header).
- minColor
- Color for minimum values (hex, e.g., "F8696B" for red).
- midColor
- Color for middle values (hex, e.g., "FFEB84" for yellow).
- maxColor
- Color for maximum values (hex, e.g., "63BE7B" for green).
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker SetColumnWidth(int col, double width)
result = openXmlExcelWorker.SetColumnWidth(col, width)
Sets the width of a column.
- col
- The column index (0-based).
- width
- The width in characters.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker SetConditionalFormatting(int col, ComparisonOperator op, string condition, string bgColor, string fgColor)
result = openXmlExcelWorker.SetConditionalFormatting(col, op, condition, bgColor, fgColor)
Sets conditional formatting for a column based on a condition.
- col
- The column index (0-based).
- op
- The ComparisonOperator to use for the condition.
- condition
- The condition value as a string.
- bgColor
- The background color to apply if the condition is met (e.g., hex code or name).
- fgColor
- The foreground (text) color to apply if the condition is met (e.g., hex code or name).
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker SetConditionalFormattingFormula(int startCol, int startRow, int endCol, int endRow, string formula, ExcelConditionalFormat format)
result = openXmlExcelWorker.SetConditionalFormattingFormula(startCol, startRow, endCol, endRow, formula, format)
Sets a formula-based ("expression") conditional formatting rule over a cell range, applying a full ExcelConditionalFormat (fill, font color/styles/size/name, number format and border) when the formula is true.
- startCol
- Range start column index (0-based).
- startRow
- Range start row index (0-based).
- endCol
- Range end column index (0-based).
- endRow
- Range end row index (0-based).
- formula
- Excel formula that returns TRUE to apply the format, without a leading '=' (e.g. $A2="OVERDUE").
- format
- The format to apply when the formula is true. Only the members that are set are written.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker SetConditionalFormattingFormula(int startCol, int startRow, int endCol, int endRow, string formula, string bgColor, string fgColor)
result = openXmlExcelWorker.SetConditionalFormattingFormula(startCol, startRow, endCol, endRow, formula, bgColor, fgColor)
Sets a formula-based ("expression") conditional formatting rule over a cell range.
- startCol
- Range start column index (0-based).
- startRow
- Range start row index (0-based).
- endCol
- Range end column index (0-based).
- endRow
- Range end row index (0-based).
- formula
- Excel formula that returns TRUE to apply the format, without a leading '=' (e.g. $A2="OVERDUE").
- bgColor
- Background fill color applied when the formula is true (hex code or name). Optional.
- fgColor
- Foreground (text) color applied when the formula is true (hex code or name). If null, the font color is left unchanged.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker SetHyperlink(int col, int row, string url, string text)
result = openXmlExcelWorker.SetHyperlink(col, row, url, text)
Sets a hyperlink in a cell.
- col
- The column index (0-based).
- row
- The row index (0-based).
- url
- The URL for the hyperlink.
- text
- The display text for the hyperlink. If null, the URL is used.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker SetRowHeight(int row, double height)
result = openXmlExcelWorker.SetRowHeight(row, height)
Sets the height of a row.
- row
- The row index (0-based).
- height
- The height in points.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker SetStyle(int col, string format)
result = openXmlExcelWorker.SetStyle(col, format)
Sets the style of a column using a custom format string.
- col
- The column index (0-based).
- format
- The format string to apply to the column.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker SetStyle(int col, Type type)
result = openXmlExcelWorker.SetStyle(col, type)
Sets the style of a column based on a specified type.
- col
- The column index (0-based).
- type
- The Type that determines the style.
Возвращает: The current IExcelWorker instance for method chaining.
public IExcelWorker SwitchSheet(string name)
result = openXmlExcelWorker.SwitchSheet(name)
Switches the active sheet to the one with the specified name.
- name
- The name of the sheet to switch to.
Возвращает: The current IExcelWorker instance for method chaining.