Example:
# First method excel = Workbook() style = excel.createStyle() style.getFont().setName("Times New Roman") style.getFont().setColor(Color.getBlue()) for i in range(0, 100): excel.getWorksheets().get(0).getCells().get(0, i).setStyle(style) # Second method style1 = excel.getWorksheets().get(0).getCells().get("A1").getStyle() style1.getFont().setName("Times New Roman") style1.getFont().setColor(Color.getBlue()) excel.getWorksheets().get(0).getCells().get("A1").setStyle(style1) # First method is a fast and efficient way to change several cell-formatting properties on multiple cells at the same time. # If you want to change a single cell's style properties, second method can be used.
Constructor Summary |
---|
Property Getters/Setters Summary | ||
---|---|---|
method | getBackgroundArgbColor() | |
method | setBackgroundArgbColor(value) | |
Gets and sets the background color with a 32-bit ARGB value. | ||
method | getBackgroundColor() | |
method | setBackgroundColor(value) | |
Gets or sets a style's background color. | ||
method | getBackgroundThemeColor() | |
method | setBackgroundThemeColor(value) | |
Gets and sets the background theme color. | ||
method | getBorders() | |
Gets the |
||
method | getCultureCustom() | |
method | setCultureCustom(value) | |
Gets and sets the culture-dependent pattern string for number format. If no number format has been set for this object, null will be returned. If number format is builtin, the pattern string corresponding to the builtin number will be returned. | ||
method | getCustom() | |
method | setCustom(value) | |
Represents the custom number format string of this style object. If the custom number format is not set(For example, the number format is builtin), "" will be returned. | ||
method | getFont() | |
Gets a |
||
method | getForegroundArgbColor() | |
method | setForegroundArgbColor(value) | |
Gets and sets the foreground color with a 32-bit ARGB value. | ||
method | getForegroundColor() | |
method | setForegroundColor(value) | |
Gets or sets a style's foreground color. | ||
method | getForegroundThemeColor() | |
method | setForegroundThemeColor(value) | |
Gets and sets the foreground theme color. | ||
method | hasBorders() | |
Checks whether there are borders have been set for the style.
|
||
method | getHorizontalAlignment() | |
method | setHorizontalAlignment(value) | |
Gets or sets the horizontal alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant. | ||
method | getIndentLevel() | |
method | setIndentLevel(value) | |
Represents the indent level for the cell or range. Can only be an integer from 0 to 250. | ||
method | getInvariantCustom() | |
Gets the culture-independent pattern string for number format.
If no number format has been set for this object, null will be returned.
If number format is builtin, the pattern string corresponding to the builtin number will be returned.
|
||
method | isAlignmentApplied() | |
method | setAlignmentApplied(value) | |
Indicate whether the alignment formatting should be applied. | ||
method | isBorderApplied() | |
method | setBorderApplied(value) | |
Indicate whether the border formatting should be applied. | ||
method | isDateTime() | |
Indicates whether the number format is a date format.
|
||
method | isFillApplied() | |
method | setFillApplied(value) | |
Indicate whether the fill formatting should be applied. | ||
method | isFontApplied() | |
method | setFontApplied(value) | |
Indicate whether the font formatting should be applied. | ||
method | isFormulaHidden() | |
method | setFormulaHidden(value) | |
Represents if the formula will be hidden when the worksheet is protected. | ||
method | isGradient() | |
method | setGradient(value) | |
Indicates whether the cell shading is a gradient pattern. | ||
method | isJustifyDistributed() | |
method | setJustifyDistributed(value) | |
Indicates if the cells justified or distributed alignment should be used on the last line of text. | ||
method | isLocked() | |
method | setLocked(value) | |
Gets or sets a value indicating whether a cell can be modified or not. | ||
method | isNumberFormatApplied() | |
method | setNumberFormatApplied(value) | |
Indicate whether the number formatting should be applied. | ||
method | isPercent() | |
Indicates whether the number format is a percent format.
|
||
method | isProtectionApplied() | |
method | setProtectionApplied(value) | |
Indicate whether the protection formatting should be applied. | ||
method | isTextWrapped() | |
method | setTextWrapped(value) | |
Gets or sets a value indicating whether the text within a cell is wrapped. | ||
method | getName() | |
method | setName(value) | |
Gets or sets the name of the style. | ||
method | getNumber() | |
method | setNumber(value) | |
Gets or sets the display format of numbers and dates. The formatting patterns are different for different regions. | ||
method | getParentStyle() | |
Gets the parent style of this style.
|
||
method | getPattern() | |
method | setPattern(value) | |
Gets or sets the cell background pattern type. The value of the property is BackgroundType integer constant. | ||
method | getQuotePrefix() | |
method | setQuotePrefix(value) | |
Indicates whether the cell's value starts with single quote mark. | ||
method | getRotationAngle() | |
method | setRotationAngle(value) | |
Represents text rotation angle. | ||
method | getShrinkToFit() | |
method | setShrinkToFit(value) | |
Represents if text automatically shrinks to fit in the available column width. | ||
method | getTextDirection() | |
method | setTextDirection(value) | |
Represents text reading order. The value of the property is TextDirectionType integer constant. | ||
method | getVerticalAlignment() | |
method | setVerticalAlignment(value) | |
Gets or sets the vertical alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant. |
Method Summary | ||
---|---|---|
method | copy(style) | |
Copies data from another style object
|
||
method | equals(obj) | |
Determines whether two Style instances are equal.
|
||
method | getTwoColorGradient() | |
Get the two-color gradient setting.
|
||
method | getTwoColorGradientSetting() | |
Get the two-color gradient setting.
|
||
method | hashCode() | |
Serves as a hash function for a Style object.
|
||
method | isModified(modifyFlag) | |
Checks whether the specified properties of the style have been modified.
Used for style of ConditionalFormattings to check whether the specified properties of this style should be used when applying the ConditionalFormattings on a cell.
|
||
method | setBorder(borderType, borderStyle, borderColor) | |
Sets the borders of the style.
|
||
method | setBorder(borderType, borderStyle, borderColor) | |
Sets the borders of the style.
|
||
method | setCustom(custom, builtinPreference) | |
Sets the Custom number format string of a cell.
|
||
method | setPatternColor(pattern, color1, color2) | |
Sets the background color.
|
||
method | setTwoColorGradient(color1, color2, gradientStyleType, variant) | |
Sets the specified fill to a two-color gradient.
|
||
method | toJson() | |
Convert |
||
method | update() | |
Apply the named style to the styles of the cells which use this named style.
It works like clicking the "ok" button after you finished modifying the style.
Only applies for named style.
|
Style()
ThemeColor getBackgroundThemeColor() / setBackgroundThemeColor(value)
ThemeColor getForegroundThemeColor() / setForegroundThemeColor(value)
String getName() / setName(value)
int getPattern() / setPattern(value)
BorderCollection getBorders()
Color getBackgroundColor() / setBackgroundColor(value)
int getBackgroundArgbColor() / setBackgroundArgbColor(value)
Color getForegroundColor() / setForegroundColor(value)
int getForegroundArgbColor() / setForegroundArgbColor(value)
boolean hasBorders()
boolean isNumberFormatApplied() / setNumberFormatApplied(value)
boolean isFontApplied() / setFontApplied(value)
boolean isAlignmentApplied() / setAlignmentApplied(value)
boolean isBorderApplied() / setBorderApplied(value)
boolean isFillApplied() / setFillApplied(value)
boolean isProtectionApplied() / setProtectionApplied(value)
int getIndentLevel() / setIndentLevel(value)
int getRotationAngle() / setRotationAngle(value)
0: Not rotated.
255: Top to Bottom.
-90: Downward.
90: Upward.
You can set 255 or value ranged from -90 to 90.int getHorizontalAlignment() / setHorizontalAlignment(value)
int getVerticalAlignment() / setVerticalAlignment(value)
boolean isTextWrapped() / setTextWrapped(value)
int getNumber() / setNumber(value)
Value | Type | Format String |
---|---|---|
0 | General | General |
1 | Decimal | 0 |
2 | Decimal | 0.00 |
3 | Decimal | #,##0 |
4 | Decimal | #,##0.00 |
5 | Currency | $#,##0_);($#,##0) |
6 | Currency | $#,##0_);[Red]($#,##0) |
7 | Currency | $#,##0.00_);($#,##0.00) |
8 | Currency | $#,##0.00_);[Red]($#,##0.00) |
9 | Percentage | 0% |
10 | Percentage | 0.00% |
11 | Scientific | 0.00E+00 |
12 | Fraction | # ?/? |
13 | Fraction | # ??/?? |
14 | Date | m/d/yyyy |
15 | Date | d-mmm-yy |
16 | Date | d-mmm |
17 | Date | mmm-yy |
18 | Time | h:mm AM/PM |
19 | Time | h:mm:ss AM/PM |
20 | Time | h:mm |
21 | Time | h:mm:ss |
22 | Time | m/d/yyyy h:mm |
37 | Accounting | #,##0_);(#,##0) |
38 | Accounting | #,##0_);[Red](#,##0) |
39 | Accounting | #,##0.00_);(#,##0.00) |
40 | Accounting | #,##0.00_);[Red](#,##0.00) |
41 | Accounting | _(* #,##0_);_(* (#,##0);_(* "-"_);_(@_) |
42 | Currency | _($* #,##0_);_($* (#,##0);_($* "-"_);_(@_) |
43 | Accounting | _(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_) |
44 | Currency | _($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_) |
45 | Time | mm:ss |
46 | Time | [h]:mm:ss |
47 | Time | mm:ss.0 |
48 | Scientific | ##0.0E+0 |
49 | Text | @ |
boolean isLocked() / setLocked(value)
String getCustom() / setCustom(value)
String getCultureCustom() / setCultureCustom(value)
String getInvariantCustom()
boolean isFormulaHidden() / setFormulaHidden(value)
boolean getShrinkToFit() / setShrinkToFit(value)
int getTextDirection() / setTextDirection(value)
boolean isJustifyDistributed() / setJustifyDistributed(value)
boolean getQuotePrefix() / setQuotePrefix(value)
boolean isGradient() / setGradient(value)
boolean isPercent()
boolean isDateTime()
setTwoColorGradient(color1, color2, gradientStyleType, variant)
color1: Color
- One gradient color.color2: Color
- Two gradient color.gradientStyleType: int
- A variant: int
- The gradient variant. Can be a value from 1 through 4, corresponding to one of the four variants on the Gradient tab in the Fill Effects dialog box. If style is GradientStyle.FromCenter, the Variant argument can only be 1 or 2.Object[] getTwoColorGradient()
TwoColorGradient getTwoColorGradientSetting()
String toJson()
setPatternColor(pattern, color1, color2)
pattern: int
- A color1: Color
- The foreground color.color2: Color
- The background color. Only works when pattern is not BackgroundType.None and BackgroundType.Solid.copy(style)
style: Style
- Source Style objectupdate()
boolean isModified(modifyFlag)
modifyFlag: int
- A boolean equals(obj)
obj: Object
- The Style object to compare with the current Style object. int hashCode()
boolean setBorder(borderType, borderStyle, borderColor)
borderType: int
- A borderStyle: int
- A borderColor: Color
- The color of the border.boolean setBorder(borderType, borderStyle, borderColor)
borderType: int
- A borderStyle: int
- A borderColor: CellsColor
- The color of the border.setCustom(custom, builtinPreference)
custom: String
- Custom number format string, should be InvariantCulture pattern.builtinPreference: boolean
- If given Custom number format string matches one of the built-in number formats
corresponding to current regional settings, whether set the number format as built-in instead of Custom.