com.aspose.cells
Class Style

java.lang.Object
    extended by com.aspose.cells.Style

public class Style 
extends java.lang.Object

Represents display style of excel document,such as font, color,alignment,border,etc. The Style object contains all style attributes (font, number format, alignment, and so on) as properties. There are two methods to set a cell's style.

Example:

//First method
int styleIndex = excel.getStyles().add();
Style style = excel.getStyles().get(styleIndex);
style.getFont().setName("Times New Roman");
style.getFont().setColor(Color.getBlue());
for (int i = 0; i < 100; i++)
{
    excel.getWorksheets().get(0).getCells().get(0, i).setStyle(style);
}

//Second method
Style 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
Style()
          
 
Property Getters/Setters Summary
com.aspose.cells.ColorgetBackgroundColor()
voidsetBackgroundColor(com.aspose.cells.Color value)
           Gets or sets a style's background color.
ThemeColorgetBackgroundThemeColor()
voidsetBackgroundThemeColor(ThemeColor value)
           Gets and sets the background theme color.
BorderCollectiongetBorders()
           Gets the BorderCollection of the style.
java.lang.StringgetCultureCustom()
voidsetCultureCustom(java.lang.String value)
           Gets and sets the culture custom number format.
java.lang.StringgetCustom()
voidsetCustom(java.lang.String value)
           Represents the custom number format string of a cell. If the custom number format is not set,we will return "".
FontgetFont()
           Gets a Font object.
com.aspose.cells.ColorgetForegroundColor()
voidsetForegroundColor(com.aspose.cells.Color value)
           Gets or sets a style's foreground color.
ThemeColorgetForegroundThemeColor()
voidsetForegroundThemeColor(ThemeColor value)
           Gets and sets the foreground theme color.
intgetHorizontalAlignment()
voidsetHorizontalAlignment(int value)
           Gets or sets the horizontal alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.
intgetIndentLevel()
voidsetIndentLevel(int value)
           Represents the m_IndentLevel level for the cell or range. Can only be an integer from 0 to 15.
booleanisDateTime()
           Indicates whether the number format is a date format.
booleanisFormulaHidden()
voidsetFormulaHidden(boolean value)
           Represents if the formula will be hidden when the worksheet is protected.
booleanisGradient()
voidsetGradient(boolean value)
           Indicates whether the cell shading is a gradient pattern.
booleanisLocked()
voidsetLocked(boolean value)
           Gets or sets a value indicating whether a cell can be modified or not.
booleanisPercent()
           Indicates whether the number format is a percent format.
booleanisTextWrapped()
voidsetTextWrapped(boolean value)
           Gets or sets a value indicating whether the text within a cell is wrapped.
java.lang.StringgetName()
voidsetName(java.lang.String value)
           Gets or sets the name of the style.
intgetNumber()
voidsetNumber(int value)
           Gets or sets the display format of numbers and dates.
StylegetParentStyle()
           Gets the parent style of this style.
intgetPattern()
voidsetPattern(int value)
           Gets or sets the cell background pattern type. The value of the property is BackgroundType integer constant.
intgetRotation()
voidsetRotation(int value)
           Represents text rotation angle.
intgetRotationAngle()
voidsetRotationAngle(int value)
           Represents text rotation angle.
booleangetShrinkToFit()
voidsetShrinkToFit(boolean value)
           Represents if text automatically shrinks to fit in the available column width.
intgetTextDirection()
voidsetTextDirection(int value)
           Represents text reading order. The value of the property is TextDirectionType integer constant.
intgetVerticalAlignment()
voidsetVerticalAlignment(int 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
voidcopy(Style style)
           Copies data from another style object
booleanequals(java.lang.Object obj)
           Determines whether two Style instances are equal.
inthashCode()
           Serves as a hash function for a Style object.
booleanisModified(int modifyFlag)
           Gets which property of the style is modified.
booleansetBorder(int borderEdge, int borderStyle, com.aspose.cells.Color borderColor)
           Sets the border of the style.
voidsetTwoColorGradient(com.aspose.cells.Color color1, com.aspose.cells.Color color2, int gradientStyleType, int variant)
           Sets the specified fill to a two-color gradient.
voidupdate()
           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.
 

Constructor Detail

Style

public Style()

Property Getters/Setters Detail

getBackgroundThemeColor/setBackgroundThemeColor

public ThemeColor getBackgroundThemeColor() / public void setBackgroundThemeColor(ThemeColor value)
Gets and sets the background theme color. If the background color is not a theme color, NULL will be returned.

getForegroundThemeColor/setForegroundThemeColor

public ThemeColor getForegroundThemeColor() / public void setForegroundThemeColor(ThemeColor value)
Gets and sets the foreground theme color. If the forground color is not a theme color, NULL will be returned.

getName/setName

public java.lang.String getName() / public void setName(java.lang.String value)
Gets or sets the name of the style.

getPattern/setPattern

public int getPattern() / public void setPattern(int value)
Gets or sets the cell background pattern type. The value of the property is BackgroundType integer constant.

getBorders

public BorderCollection getBorders()
Gets the BorderCollection of the style.

getBackgroundColor/setBackgroundColor

public com.aspose.cells.Color getBackgroundColor() / public void setBackgroundColor(com.aspose.cells.Color value)
Gets or sets a style's background color. If you want to set a cell's color, please use Style.ForegroundColor property. Only if the cell style pattern is other than none or solid, this property will take effect.

getForegroundColor/setForegroundColor

public com.aspose.cells.Color getForegroundColor() / public void setForegroundColor(com.aspose.cells.Color value)
Gets or sets a style's foreground color. It means no color setting if Color.Empty is returned.

getParentStyle

public Style getParentStyle()
Gets the parent style of this style.

getIndentLevel/setIndentLevel

public int getIndentLevel() / public void setIndentLevel(int value)
Represents the m_IndentLevel level for the cell or range. Can only be an integer from 0 to 15. If text horizontal alignment type is set to value other than left or right, m_IndentLevel level will be reset to zero.

getFont

public Font getFont()
Gets a Font object.

getRotationAngle/setRotationAngle

public int getRotationAngle() / public void setRotationAngle(int value)
Represents text rotation angle.

0: Not rotated.

255: Top to Bottom.

-90: Downward.

90: Upward.

You can set 255 or value ranged from -90 to 90.

getRotation/setRotation

public int getRotation() / public void setRotation(int value)
Represents text rotation angle.

0: Not rotated.

255: Top to Bottom.

-90: Downward.

90: Upward.

You can set 255 or value ranged from -90 to 90.
NOTE: This member is now obsolete. Instead, please use Style.RotationAngle property. This property will be removed 12 months later since June 2010. Aspose apologizes for any inconvenience you may have experienced.

getVerticalAlignment/setVerticalAlignment

public int getVerticalAlignment() / public void setVerticalAlignment(int value)
Gets or sets the vertical alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.

getHorizontalAlignment/setHorizontalAlignment

public int getHorizontalAlignment() / public void setHorizontalAlignment(int value)
Gets or sets the horizontal alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.

isTextWrapped/setTextWrapped

public boolean isTextWrapped() / public void setTextWrapped(boolean value)
Gets or sets a value indicating whether the text within a cell is wrapped.

getNumber/setNumber

public int getNumber() / public void setNumber(int value)
Gets or sets the display format of numbers and dates.
Value Type Format String 
0GeneralGeneral
1Decimal0
2Decimal0.00
3Decimal#,##0
4Decimal#,##0.00
5Currency$#,##0;($#,##0)
6Currency$#,##0;[Red]($#,##0)
7Currency$#,##0.00;($#,##0.00)
8Currency$#,##0.00;[Red]($#,##0.00)
9Percentage0%
10Percentage0.00%
11Scientific0.00E+00
12Fraction# ?/?
13Fraction# ??/??
14Datem/d/yyyy
15Dated-mmm-yy
16Dated-mmm
17Datemmm-yy
18Timeh:mm AM/PM
19Timeh:mm:ss AM/PM
20Timeh:mm
21Timeh:mm:ss
22Timem/d/yyyy h:mm
37Accounting#,##0;(#,##0)
38Accounting#,##0;[Red](#,##0)
39Accounting#,##0.00;(#,##0.00)
40Accounting#,##0.00;[Red](#,##0.00)
41Accounting_ * #,##0_ ;_ * (#,##0)_ ;_ * "-"_ ;_ @_
42Currency_ $* #,##0_ ;_ $* (#,##0)_ ;_ $* "-"_ ;_ @_
43Accounting_ * #,##0.00_ ;_ * (#,##0.00)_ ;_ * "-"??_ ;_ @_
44Currency_ $* #,##0.00_ ;_ $* (#,##0.00)_ ;_ $* "-"??_ ;_ @_
45Timemm:ss
46Time[h]:mm:ss
47Timemm:ss.0
48Scientific##0.0E+00
49Text@

isLocked/setLocked

public boolean isLocked() / public void setLocked(boolean value)
Gets or sets a value indicating whether a cell can be modified or not. Locking cells has no effect unless the worksheet is protected.

getCustom/setCustom

public java.lang.String getCustom() / public void setCustom(java.lang.String value)
Represents the custom number format string of a cell. If the custom number format is not set,we will return "". It should be InvariantCulture .

getCultureCustom/setCultureCustom

public java.lang.String getCultureCustom() / public void setCultureCustom(java.lang.String value)
Gets and sets the culture custom number format.

isFormulaHidden/setFormulaHidden

public boolean isFormulaHidden() / public void setFormulaHidden(boolean value)
Represents if the formula will be hidden when the worksheet is protected.

getShrinkToFit/setShrinkToFit

public boolean getShrinkToFit() / public void setShrinkToFit(boolean value)
Represents if text automatically shrinks to fit in the available column width.

getTextDirection/setTextDirection

public int getTextDirection() / public void setTextDirection(int value)
Represents text reading order. The value of the property is TextDirectionType integer constant.

isGradient/setGradient

public boolean isGradient() / public void setGradient(boolean value)
Indicates whether the cell shading is a gradient pattern.

isPercent

public boolean isPercent()
Indicates whether the number format is a percent format.

isDateTime

public boolean isDateTime()
Indicates whether the number format is a date format.

Method Detail

copy

public void copy(Style style)
Copies data from another style object This method does not copy the name of the style. If you want to copy the name ,please call the following codes after copying style: destStyle.Name = style.Name.
Parameters:
style - Source Style object

update

public void 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.

isModified

public boolean isModified(int modifyFlag)
Gets which property of the style is modified.
Parameters:
modifyFlag - A StyleModifyFlag value.
Returns:

equals

public boolean equals(java.lang.Object obj)
Determines whether two Style instances are equal.
Parameters:
obj - The Style object to compare with the current Style object.
Returns:
true if the specified Object is equal to the current Object; otherwise, false.

hashCode

public int hashCode()
Serves as a hash function for a Style object. This method is only for internal use.
Returns:
A hash code for the current Object.

setBorder

public boolean setBorder(int borderEdge, int borderStyle, com.aspose.cells.Color borderColor)
Sets the border of the style.
Parameters:
borderEdge - A BorderType value.
borderStyle - A CellBorderType value.
borderColor -
Returns:

setTwoColorGradient

public void setTwoColorGradient(com.aspose.cells.Color color1, com.aspose.cells.Color color2, int gradientStyleType, int variant)
Sets the specified fill to a two-color gradient.
Parameters:
color1 - One gradient color.
color2 - Two gradient color.
gradientStyleType - A GradientStyleType value. Gradient shading style.
variant - 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.

See Also:
          Aspose.Cells Documentation - the home page for the Aspose.Cellss Product Documentation.
          Aspose.Cells Support Forum - our preferred method of support.