Method SetValue
SetValue(int, int, XlsxCellValue)
Sets a cell's value. A formula the cell had is removed; its format is kept.
public void SetValue(int row, int column, XlsxCellValue value)
Parameters
rowintThe one-based row, 1 to 1,048,576.
columnintThe one-based column, 1 to 16,384.
valueXlsxCellValueThe value. Blank empties the cell and keeps it for its format.
Remarks
The cell need not exist. Text is written into the cell itself (an inline string); the workbook's shared string table is not rewritten. A date is a number: give the cell a date number format with SetStyle(int, int, XlsxCellStyle) for it to show as one.
Nothing is calculated. Formulas that depend on the cell keep the results the file had until the workbook is opened in an application that calculates; the saved workbook asks for that calculation.
Exceptions
- ArgumentOutOfRangeException
The row or the column is outside the worksheet grid.
- ArgumentException
The value is text longer than the 32,767 characters a cell holds.
- InvalidOperationException
The sheet is not a worksheet.
- UnsupportedFeatureException
The cell is part of an array formula entered over several cells, or is a header or totals cell of a table.
- InvalidDocumentException
The sheet's part is malformed.
SetValue(string, XlsxCellValue)
Sets a cell's value by its reference. See SetValue(int, int, XlsxCellValue).
public void SetValue(string reference, XlsxCellValue value)
Parameters
referencestringThe reference, such as
B4.valueXlsxCellValueThe value.
Exceptions
- ArgumentNullException
referenceis null.- ArgumentException
referenceis not a cell reference inside the worksheet grid, or the value is too long.- InvalidOperationException
The sheet is not a worksheet.
- UnsupportedFeatureException
The cell is part of an array formula entered over several cells, or is a header or totals cell of a table.
- InvalidDocumentException
The sheet's part is malformed.