Example:
excel = Workbook() cells = excel.getWorksheets().get(0).getCells() # Put a string into a cell cell = cells.get(0, 0) cell.putValue("Hello") first = cell.getStringValue() # Put an integer into a cell cell = cells.get("B1") cell.putValue(12) second = cell.getIntValue() # Put a double into a cell cell = cells.get(0, 2) cell.putValue(-1.234) third = cell.getDoubleValue() # Put a formula into a cell cell = cells.get("D1") cell.setFormula("=B1 + C1") # Put a combined formula: "sum(average(b1,c1), b1)" to cell at b2 cell = cells.get("b2") cell.setFormula("=sum(average(b1,c1), b1)") # Set style of a cell style = cell.getStyle() # Set background color style.setBackgroundColor(Color.getYellow()) # Set format of a cell style.getFont().setName("Courier New") style.setVerticalAlignment(TextAlignmentType.TOP) cell.setStyle(style)
Property Getters/Setters Summary | ||
---|---|---|
method | getBoolValue() | |
Gets the boolean value contained in the cell.
|
||
method | getColumn() | |
Gets column number (zero based) of the cell.
|
||
method | getComment() | |
Gets the comment of this cell.
|
||
method | containsExternalLink() | |
Indicates whether this cell contains an external link.
Only applies when the cell is a formula cell.
|
||
method | getDateTimeValue() | |
Gets the DateTime value contained in the cell.
|
||
method | getDisplayStringValue() | |
Gets the formatted string value of this cell by cell's display style.
|
||
method | getDoubleValue() | |
Gets the double value contained in the cell.
|
||
method | getEmbeddedImage() | |
method | setEmbeddedImage(value) | |
Gets and sets the embeddedn image in the cell. | ||
method | getFloatValue() | |
Gets the float value contained in the cell.
|
||
method | getFormula() | |
method | setFormula(value) | |
Gets or sets a formula of the |
||
method | getFormulaLocal() | |
method | setFormulaLocal(value) | |
Get the locale formatted formula of the cell. | ||
method | hasCustomStyle() | |
Indicates whether this cell has custom style settings(different from the default one inherited
from corresponding row, column, or workbook).
|
||
method | getHtmlString() | |
method | setHtmlString(value) | |
Gets and sets the html string which contains data and some formats in this cell. | ||
method | getIntValue() | |
Gets the integer value contained in the cell.
|
||
method | isArrayFormula() | |
Indicates whether the cell formula is an array formula.
|
||
method | isArrayHeader() | |
Indicates the cell's formula is an array formula
and it is the first cell of the array.
|
||
method | isDynamicArrayFormula() | |
Indicates whether the cell's formula is dynamic array formula(true) or legacy array formula(false).
|
||
method | isErrorValue() | |
Checks if the value of this cell is an error.
|
||
method | isFormula() | |
Represents if the specified cell contains formula.
|
||
method | isInArray() | |
Indicates whether the cell formula is an array formula.
|
||
method | isInTable() | |
Indicates whether this cell is part of table formula.
|
||
method | isMerged() | |
Checks if a cell is part of a merged range or not.
|
||
method | isNumericValue() | |
Indicates whether the value of this cell is numeric(int, double and datetime)
|
||
method | isSharedFormula() | |
Indicates whether the cell formula is part of shared formula.
|
||
method | isStyleSet() | |
Indicates if the cell's style is set. If return false, it means this cell has a default cell format.
|
||
method | isTableFormula() | |
Indicates whether this cell is part of table formula.
|
||
method | getName() | |
Gets the name of the cell.
|
||
method | getNumberCategoryType() | |
Represents the category type of this cell's number formatting.
The value of the property is NumberCategoryType integer constant. |
||
method | getR1C1Formula() | |
method | setR1C1Formula(value) | |
Gets or sets a R1C1 formula of the |
||
method | getRow() | |
Gets row number (zero based) of the cell.
|
||
method | getSharedStyleIndex() | |
Gets cell's shared style index in the style pool.
|
||
method | getStringValue() | |
Gets the string value contained in the cell. If the type of this cell is string, then return the string value itself.
For other cell types, the formatted string value (formatted with the specified style of this cell) will be returned.
The formatted cell value is same with what you can get from excel when copying a cell as text(such as
copying cell to text editor or exporting to csv).
|
||
method | getStringValueWithoutFormat() | |
Gets cell's value as string without any format.
|
||
method | getType() | |
Represents cell value type.
The value of the property is CellValueType integer constant. |
||
method | getValue() | |
method | setValue(value) | |
Gets/sets the value contained in this cell. | ||
method | getWorksheet() | |
Gets the parent worksheet.
|
Method Summary | ||
---|---|---|
method | calculate(options) | |
Calculates the formula of the cell.
|
||
method | characters(startIndex, length) | |
Returns a Characters object that represents a range of characters within the cell text.
|
||
method | copy(cell) | |
Copies data from a source cell.
|
||
method | equals(cell) | |
Checks whether this object refers to the same cell with another cell object.
|
||
method | equals(obj) | |
Checks whether this object refers to the same cell with another.
|
||
method | getArrayRange() | |
Gets the array range if the cell's formula is an array formula.
|
||
method | getCharacters() | |
Returns all Characters objects
that represents a range of characters within the cell text.
|
||
method | getCharacters(flag) | |
Returns all Characters objects
that represents a range of characters within the cell text.
|
||
method | getConditionalFormattingResult() | |
Get the result of the conditional formatting.
|
||
method | getDependents(isAll) | |
Get all cells whose formula references to this cell directly.
|
||
method | getDependentsInCalculation(recursive) | |
Gets all cells whose calculated result depends on this cell.
|
||
method | getDisplayStyle() | |
Gets the display style of the cell.
If this cell is also affected by other settings such as conditional formatting, list objects, etc.,
then the display style may be different from cell.GetStyle().
|
||
method | getDisplayStyle(includeMergedBorders) | |
Gets the display style of the cell.
If the cell is conditional formatted, the display style is not same as the cell.GetStyle().
|
||
method | getFormatConditions() | |
Gets format conditions which applies to this cell.
|
||
method | getFormula(isR1C1, isLocal) | |
Get the formula of this cell.
|
||
method | getHeightOfValue() | |
Gets the height of the value in unit of pixels.
|
||
method | getHtmlString(html5) | |
Gets the html string which contains data and some formats in this cell.
|
||
method | getLeafs() | |
Get all cells which reference to this cell directly and need to be updated when this cell is modified.
|
||
method | getLeafs(recursive) | |
Get all cells which will be updated when this cell is modified.
|
||
method | getMergedRange() | |
Returns a |
||
method | getPrecedents() | |
Gets all references appearing in this cell's formula.
|
||
method | getPrecedentsInCalculation() | |
Gets all precedents(reference to cells in current workbook) used by this cell's formula while calculating it.
|
||
method | getStringValue(formatStrategy) | |
Gets the string value by specific formatted strategy.
|
||
method | getStyle() | |
Gets the cell style.
|
||
method | getStyle(checkBorders) | |
If checkBorders is true, check whether other cells' borders will effect the style of this cell.
|
||
method | getTable() | |
Gets the table which contains this cell.
|
||
method | getValidation() | |
Gets the validation applied to this cell.
|
||
method | getValidationValue() | |
Gets the value of validation which applied to this cell.
|
||
method | getWidthOfValue() | |
Gets the width of the value in unit of pixels.
|
||
method | hashCode() | |
Serves as a hash function for a particular type.
|
||
method | insertText(index, text) | |
Insert some characters to the cell.
If the cell is rich formatted, this method could keep the original formatting.
|
||
method | isRichText() | |
Indicates whether the string value of this cell is a rich formatted text.
|
||
method | putValue(boolValue) | |
Puts a boolean value into the cell.
|
||
method | putValue(dateTime) | |
Puts a DateTime value into the cell.
|
||
method | putValue(doubleValue) | |
Puts a double value into the cell.
|
||
method | putValue(intValue) | |
Puts an integer value into the cell.
|
||
method | putValue(objectValue) | |
Puts an object value into the cell.
|
||
method | putValue(stringValue) | |
Puts a string value into the cell.
|
||
method | putValue(stringValue, isConverted) | |
Puts a string value into the cell and converts the value to other data type if appropriate.
|
||
method | putValue(stringValue, isConverted, setStyle) | |
Puts a value into the cell, if appropriate the value will be converted to other data type and cell's number format will be reset.
|
||
method | removeArrayFormula(leaveNormalFormula) | |
Remove array formula.
|
||
method | replace(placeHolder, newValue, options) | |
Replace text of the cell with options.
|
||
method | setArrayFormula(arrayFormula, rowNumber, columnNumber) | |
Sets an array formula(legacy array formula entered via CTRL+SHIFT+ENTER in ms excel) to a range of cells.
|
||
method | setArrayFormula(arrayFormula, rowNumber, columnNumber, isR1C1, isLocal) | |
Sets an array formula to a range of cells.
|
||
method | setArrayFormula(arrayFormula, rowNumber, columnNumber, options) | |
Sets an array formula to a range of cells.
|
||
method | setArrayFormula(arrayFormula, rowNumber, columnNumber, options, values) | |
Sets an array formula to a range of cells.
|
||
method | setCharacters(characters) | |
Sets rich text format of the cell.
|
||
method | setDynamicArrayFormula(arrayFormula, options, calculateValue) | |
Sets dynamic array formula and make the formula spill into neighboring cells if possible.
|
||
method | setDynamicArrayFormula(arrayFormula, options, values, calculateRange, calculateValue) | |
Sets dynamic array formula and make the formula spill into neighboring cells if possible.
|
||
method | setDynamicArrayFormula(arrayFormula, options, values, calculateRange, calculateValue, copts) | |
Sets dynamic array formula and make the formula spill into neighboring cells if possible.
|
||
method | setFormula(formula, isR1C1, isLocal, value) | |
Set the formula and the value of the formula.
|
||
method | setFormula(formula, options, value) | |
Set the formula and the value(calculated result) of the formula.
|
||
method | setFormula(formula, value) | |
Set the formula and the value(calculated result) of the formula.
|
||
method | setSharedFormula(sharedFormula, rowNumber, columnNumber) | |
Sets shared formulas to a range of cells.
|
||
method | setSharedFormula(sharedFormula, rowNumber, columnNumber, isR1C1, isLocal) | |
Sets a formula to a range of cells.
|
||
method | setSharedFormula(sharedFormula, rowNumber, columnNumber, options) | |
Sets shared formulas to a range of cells.
|
||
method | setSharedFormula(sharedFormula, rowNumber, columnNumber, options, values) | |
Sets shared formulas to a range of cells.
|
||
method | setStyle(style) | |
Sets the cell style.
|
||
method | setStyle(style, explicitFlag) | |
Apply the changed property of style to the cell.
|
||
method | setStyle(style, flag) | |
Apply the cell style based on flags.
|
||
method | setTableFormula(rowNumber, columnNumber, rowIndexOfInputCell, columnIndexOfInputCell, isRowInput, values) | |
Create one-variable data table for given range starting from this cell.
|
||
method | setTableFormula(rowNumber, columnNumber, rowIndexOfRowInputCell, columnIndexOfRowInputCell, rowIndexOfColumnInputCell, columnIndexOfColumnInputCell, values) | |
Create two-variable data table for given range starting from this cell.
|
||
method | setTableFormula(rowNumber, columnNumber, inputCell, isRowInput, values) | |
Create one-variable data table for given range starting from this cell.
|
||
method | setTableFormula(rowNumber, columnNumber, rowInputCell, columnInputCell, values) | |
Create two-variable data table for given range starting from this cell.
|
||
method | toJson() | |
Convert |
||
method | toString() | |
Returns a string represents the current Cell object.
|
DateTime getDateTimeValue()
int getRow()
int getColumn()
boolean isFormula()
int getType()
String getName()
boolean isErrorValue()
boolean isNumericValue()
String getStringValue()
String getStringValueWithoutFormat()
int getNumberCategoryType()
String getDisplayStringValue()
int getIntValue()
float getDoubleValue()
float getFloatValue()
boolean getBoolValue()
boolean hasCustomStyle()
int getSharedStyleIndex()
String getFormula() / setFormula(value)
Example:
excel = Workbook() cells = excel.getWorksheets().get(0).getCells() cells.get("B6").setFormula("=SUM(B2:B5, E1) + sheet2!A1")
String getFormulaLocal() / setFormulaLocal(value)
String getR1C1Formula() / setR1C1Formula(value)
boolean containsExternalLink()
boolean isArrayHeader()
boolean isDynamicArrayFormula()
boolean isArrayFormula()
boolean isInArray()
boolean isSharedFormula()
boolean isTableFormula()
boolean isInTable()
Object getValue() / setValue(value)
null,
Boolean,
DateTime,
Double,
Integer
String.
For int value, it may be returned as an Integer object or a Double object. And there is no guarantee that the returned value will be kept as the same type of object always.boolean isStyleSet()
boolean isMerged()
Comment getComment()
String getHtmlString() / setHtmlString(value)
byte[] getEmbeddedImage() / setEmbeddedImage(value)
CellArea setDynamicArrayFormula(arrayFormula, options, calculateValue)
arrayFormula: String
- the formula expressionoptions: FormulaParseOptions
- options to parse formula.
"Parse" option will be ignored and the formula will always be parsed immediatelycalculateValue: boolean
- whether calculate this dynamic array formula for those cells in the spilled range.CellArea setDynamicArrayFormula(arrayFormula, options, values, calculateRange, calculateValue)
arrayFormula: String
- the formula expressionoptions: FormulaParseOptions
- options to parse formula.
"Parse" option will be ignored and the formula will always be parsed immediatelyvalues: Object[][]
- values(calculated results) for those cells with given dynamic array formulacalculateRange: boolean
-
Whether calculate the spilled range for this dynamic array formula.
If the "values" parameter is not null and this flag is false,
then the spilled range's height will be values.Length and width will be values[0].Length.
calculateValue: boolean
-
whether calculate this dynamic array formula for those cells in the spilled range when "values" is null
or corresponding item in "values" for one cell is null.
CellArea setDynamicArrayFormula(arrayFormula, options, values, calculateRange, calculateValue, copts)
arrayFormula: String
- the formula expressionoptions: FormulaParseOptions
- options to parse formula.
"Parse" option will be ignored and the formula will always be parsed immediatelyvalues: Object[][]
- values(calculated results) for those cells with given dynamic array formulacalculateRange: boolean
-
Whether calculate the spilled range for this dynamic array formula.
If the "values" parameter is not null and this flag is false,
then the spilled range's height will be values.Length and width will be values[0].Length.
calculateValue: boolean
-
whether calculate this dynamic array formula for those cells in the spilled range when "values" is null
or corresponding item in "values" for one cell is null.
copts: CalculationOptions
- The options for calculating formula.
Commonly, for performance consideration, the setTableFormula(rowNumber, columnNumber, rowInputCell, columnInputCell, values)
rowNumber: int
- Number of rows to populate the formula.columnNumber: int
- Number of columns to populate the formula.rowInputCell: String
- the row input cellcolumnInputCell: String
- the column input cellvalues: Object[][]
- values for cells in table formula rangesetTableFormula(rowNumber, columnNumber, inputCell, isRowInput, values)
rowNumber: int
- Number of rows to populate the formula.columnNumber: int
- Number of columns to populate the formula.inputCell: String
- the input cellisRowInput: boolean
- Indicates whether the input cell is a row input cell(true) or a column input cell(false).values: Object[][]
- values for cells in table formula rangesetTableFormula(rowNumber, columnNumber, rowIndexOfRowInputCell, columnIndexOfRowInputCell, rowIndexOfColumnInputCell, columnIndexOfColumnInputCell, values)
rowNumber: int
- Number of rows to populate the formula.columnNumber: int
- Number of columns to populate the formula.rowIndexOfRowInputCell: int
- row index of the row input cellcolumnIndexOfRowInputCell: int
- column index of the row input cellrowIndexOfColumnInputCell: int
- row index of the column input cellcolumnIndexOfColumnInputCell: int
- column index of the column input cellvalues: Object[][]
- values for cells in table formula rangesetTableFormula(rowNumber, columnNumber, rowIndexOfInputCell, columnIndexOfInputCell, isRowInput, values)
rowNumber: int
- Number of rows to populate the formula.columnNumber: int
- Number of columns to populate the formula.rowIndexOfInputCell: int
- row index of the input cellcolumnIndexOfInputCell: int
- column index of the input cellisRowInput: boolean
- Indicates whether the input cell is a row input cell(true) or a column input cell(false).values: Object[][]
- values for cells in table formula rangeremoveArrayFormula(leaveNormalFormula)
leaveNormalFormula: boolean
- True represents converting the array formula to normal formula.copy(cell)
cell: Cell
- Source FontSetting characters(startIndex, length)
startIndex: int
- The index of the start of the character.length: int
- The number of characters.Example:
excel = Workbook() excel.getWorksheets().get(0).getCells().get("A1").putValue("Helloworld") excel.getWorksheets().get(0).getCells().get("A1").characters(5, 5).getFont().setBold(True) excel.getWorksheets().get(0).getCells().get("A1").characters(5, 5).getFont().setColor(Color.getBlue())
replace(placeHolder, newValue, options)
placeHolder: String
- Cell placeholdernewValue: String
- String value to replaceoptions: ReplaceOptions
- The replace optionsinsertText(index, text)
index: int
- The index.text: String
- Inserted text.boolean isRichText()
FontSetting[] getCharacters()
FontSetting[] getCharacters(flag)
flag: boolean
- Indicates whether applying table style to the cell if the cell is in the table.setCharacters(characters)
characters: FontSetting[]
- All Characters objects.Range getMergedRange()
String getHtmlString(html5)
html5: boolean
- Indicates whether the value is compatible for html5String toString()
String toJson()
boolean equals(obj)
obj: Object
- another objectint hashCode()
boolean equals(cell)
cell: Cell
- another cell objectConditionalFormattingResult getConditionalFormattingResult()
Validation getValidation()
boolean getValidationValue()
ListObject getTable()
calculate(options)
options: CalculationOptions
- Options for calculationputValue(boolValue)
boolValue: boolean
- putValue(intValue)
intValue: int
- Input valueputValue(doubleValue)
doubleValue: float
- Input valueputValue(stringValue, isConverted, setStyle)
stringValue: String
- Input valueisConverted: boolean
- True: converted to other data type if appropriate.setStyle: boolean
- True: set the number format to cell's style when converting to other data typeputValue(stringValue, isConverted)
stringValue: String
- Input valueisConverted: boolean
- True: converted to other data type if appropriate.putValue(stringValue)
stringValue: String
- Input valueputValue(dateTime)
dateTime: DateTime
- Input valueputValue(objectValue)
objectValue: Object
- input valueString getStringValue(formatStrategy)
formatStrategy: int
- A int getWidthOfValue()
int getHeightOfValue()
Style getDisplayStyle()
Style getDisplayStyle(includeMergedBorders)
includeMergedBorders: boolean
- Indicates whether checking borders of the merged cells.FormatConditionCollection[] getFormatConditions()
Style getStyle()
Style getStyle(checkBorders)
checkBorders: boolean
- Check other cells' borderssetStyle(style)
style: Style
- The cell style.setStyle(style, explicitFlag)
style: Style
- The cell style.explicitFlag: boolean
- True, only overwriting formatting which is explicitly set.
setStyle(style, flag)
style: Style
- The cell style.flag: StyleFlag
- The style flag.setFormula(formula, value)
formula: String
- The formula.value: Object
- The value(calculated result) of the formula.String getFormula(isR1C1, isLocal)
isR1C1: boolean
- Whether the formula needs to be formatted as R1C1.isLocal: boolean
- Whether the formula needs to be formatted by locale.setFormula(formula, isR1C1, isLocal, value)
formula: String
- The formula.isR1C1: boolean
- Whether the formula is R1C1 formula.isLocal: boolean
- Whether the formula is locale formatted.value: Object
- The value of the formula.setFormula(formula, options, value)
formula: String
- The formula.options: FormulaParseOptions
- Options for parsing the formula.value: Object
- The value(calculated result) of the formula.setArrayFormula(arrayFormula, rowNumber, columnNumber, isR1C1, isLocal)
arrayFormula: String
- Array formula.rowNumber: int
- Number of rows to populate result of the array formula.columnNumber: int
- Number of columns to populate result of the array formula.isR1C1: boolean
- whether the formula is R1C1 formulaisLocal: boolean
- whether the formula is locale formattedsetArrayFormula(arrayFormula, rowNumber, columnNumber)
arrayFormula: String
- Array formula.rowNumber: int
- Number of rows to populate result of the array formula.columnNumber: int
- Number of columns to populate result of the array formula.setArrayFormula(arrayFormula, rowNumber, columnNumber, options)
arrayFormula: String
- Array formula.rowNumber: int
- Number of rows to populate result of the array formula.columnNumber: int
- Number of columns to populate result of the array formula.options: FormulaParseOptions
- Options for parsing the formula.setArrayFormula(arrayFormula, rowNumber, columnNumber, options, values)
arrayFormula: String
- Array formula.rowNumber: int
- Number of rows to populate result of the array formula.columnNumber: int
- Number of columns to populate result of the array formula.options: FormulaParseOptions
- Options for parsing the formula.values: Object[][]
- values for those cells with given array formulasetSharedFormula(sharedFormula, rowNumber, columnNumber, isR1C1, isLocal)
sharedFormula: String
- Shared formula.rowNumber: int
- Number of rows to populate the formula.columnNumber: int
- Number of columns to populate the formula.isR1C1: boolean
- whether the formula is R1C1 formulaisLocal: boolean
- whether the formula is locale formattedsetSharedFormula(sharedFormula, rowNumber, columnNumber)
sharedFormula: String
- Shared formula.rowNumber: int
- Number of rows to populate the formula.columnNumber: int
- Number of columns to populate the formula.setSharedFormula(sharedFormula, rowNumber, columnNumber, options)
sharedFormula: String
- Shared formula.rowNumber: int
- Number of rows to populate the formula.columnNumber: int
- Number of columns to populate the formula.options: FormulaParseOptions
- Options for parsing the formula.setSharedFormula(sharedFormula, rowNumber, columnNumber, options, values)
sharedFormula: String
- Shared formula.rowNumber: int
- Number of rows to populate the formula.columnNumber: int
- Number of columns to populate the formula.options: FormulaParseOptions
- Options for parsing the formula.values: Object[][]
- values for those cells with given shared formulaReferredAreaCollection getPrecedents()
Example:
workbook = Workbook() cells = workbook.getWorksheets().get(0).getCells() cells.get("A1").setFormula("= B1 + SUM(B1:B10) + [Book2.xlsx]Chart!B2") areas = cells.get("A1").getPrecedents() for i in range(0, areas.getCount()): area = areas.get(i) stringBuilder = "" if area.isExternalLink(): stringBuilder += "[" stringBuilder += str(area.getExternalFileName()) stringBuilder += "]" stringBuilder += str(area.getSheetName()) stringBuilder += "!" stringBuilder += str(CellsHelper.cellIndexToName(area.getStartRow(), area.getStartColumn())) if area.isArea(): stringBuilder += ":" stringBuilder += str(CellsHelper.cellIndexToName(area.getEndRow(), area.getEndColumn())) workbook.save("Book1.xlsx")
Cell[] getDependents(isAll)
isAll: boolean
- Indicates whether check formulas in other worksheetsIterator getPrecedentsInCalculation()
Iterator getDependentsInCalculation(recursive)
recursive: boolean
- Whether returns those dependents which do not reference to this cell directly
but reference to other leafs of this cell Iterator getLeafs()
Iterator getLeafs(recursive)
recursive: boolean
- Whether returns those leafs that do not reference to this cell directly
but reference to other leafs of this cellCellArea getArrayRange()