public class StyleParser
extends java.lang.Object
A StyleParser
parses "CSS" text, from beginning to end, in a
CSS-like format:
[.styleName { propertyName: value [; propertyName: value]* }]*
If a property value is an empty string or the property is not present, then it will be ignored. Unrecognized property names and unrecognized values for a property are ignored. Property names and values may be specified in a case insensitive-fashion, i.e. "CENTER" = "Center" = "center".
Both CSS files and the "style" attribute of the "style" tag recognize the following property names.
Properties: The following properties control alignment, borders, colors, etc., everything but the font characteristics.
alignment
- Controls horizontal alignment, with one of
the values taken from Alignment.toString()
.border
- Controls all 4 borders for the cell, with one
of the values taken from BorderType.toString()
.border-bottom
- Controls the bottom border for the cell,
with one of the values taken from BorderType.toString()
.border-left
- Controls the left border for the cell,
with one of the values taken from BorderType.toString()
.border-right
- Controls the right border for the cell,
with one of the values taken from BorderType.toString()
.border-top
- Controls the top border for the cell,
with one of the values taken from BorderType.toString()
.border-color
- Controls the color of all 4 borders for
the cell, with a hex value ("#rrggbb") or one of 48 Excel-based color
names defined by ExcelColor.toString()
. For ".xls" files,
if a hex value is supplied, then the supported color name that is closest
to the given value is used.bottom-border-color
- Controls the color of the bottom
border for the cell, with a hex value ("#rrggbb") or one of the above 48
color names mentioned above.left-border-color
- Controls the color of the left
border for the cell, with a hex value ("#rrggbb") or one of the above 48
color names mentioned above.right-border-color
- Controls the color of the right
border for the cell, with a hex value ("#rrggbb") or one of the above 48
color names mentioned above.top-border-color
- Controls the color of the top
border for the cell, with a hex value ("#rrggbb") or one of the above 48
color names mentioned above.column-width-in-chars
- Controls the width of the cell's
column, in number of characters.data-format
- Controls the Excel numeric or date format
string.fill-background-color
- Controls the "background color"
of the fill pattern, with one of the color values mentioned above.fill-foreground-color
- Controls the "foreground color"
of the fill pattern, with one of the color values mentioned above.fill-pattern
- Controls the "fill pattern", with one of
the values taken from FillPattern.toString()
:hidden
- Controls the "hidden" property with a
true
or false
value.indention
- Controls the number of characters that the
text is indented.locked
- Controls the "locked" property with a
true
or false
value.rotation
- Controls the number of degrees the text is
rotated, from -90 to +90, or ROTATION_STACKED
for stacked
text.row-height-in-points
- Controls the height of the cell's
row, in points.vertical-alignment
- Controls horizontal alignment, with
one of the values taken from VerticalAlignment.toString()
:wrap-text
- Controls whether long text values are
wrapped onto the next physical line with a cell, with a true
or false
value.Properties: The following properties control the font characteristics.
font-weight
- Controls how bold the text appears, with
the values taken from FontBoldweight.toString()
.font-charset
- Controls the character set, with the
values taken from Charset.toString()
.font-color
- Controls the color of the text, with a hex
value ("#rrggbb") or one of the color names mentioned above.font-height-in-points
- Controls the font height, in
points.font-name
- Controls the font name, e.g. "Arial".font-italic
- Controls whether the text is
italic, with a true
or false
value.font-strikeout
- Controls whether the text is
strikeout, with a
true
or false
value.font-type-offset
- Controls the text offset, e.g.
superscript and subscript, with the values taken
from FontTypeOffset.toString()
.font-underline
- Controls whether and how the text is
underlined, with the values taken from Underline.toString()
.Modifier and Type | Field | Description |
---|---|---|
static short |
POI_ROTATION_STACKED |
POI value of rotation to use to produce vertically
|
static java.lang.String |
PROPERTY_ALIGNMENT |
The property to specify horizontal alignment of the text.
|
static java.lang.String |
PROPERTY_BORDER |
The property to specify the type of all 4 borders.
|
static java.lang.String |
PROPERTY_BORDER_BOTTOM |
The property to specify the type of the bottom border.
|
static java.lang.String |
PROPERTY_BORDER_COLOR |
The property to specify the color of all 4 borders.
|
static java.lang.String |
PROPERTY_BORDER_LEFT |
The property to specify the type of the left border.
|
static java.lang.String |
PROPERTY_BORDER_RIGHT |
The property to specify the type of the right border.
|
static java.lang.String |
PROPERTY_BORDER_TOP |
The property to specify the type of the top border.
|
static java.lang.String |
PROPERTY_BOTTOM_BORDER_COLOR |
The property to specify the color of the bottom border.
|
static java.lang.String |
PROPERTY_COLUMN_WIDTH_IN_CHARS |
The property to specify the width of the column in number of characters.
|
static java.lang.String |
PROPERTY_DATA_FORMAT |
The property to specify the numeric or date data format string.
|
static java.lang.String |
PROPERTY_FILL_BACKGROUND_COLOR |
The property to specify the fill background color to be used in a fill
pattern.
|
static java.lang.String |
PROPERTY_FILL_FOREGROUND_COLOR |
The property to specify the fill foreground color to be used in a fill
pattern.
|
static java.lang.String |
PROPERTY_FILL_PATTERN |
The property to specify the fill pattern to be used with the fill
foreground color and the fill background color.
|
static java.lang.String |
PROPERTY_FONT_BOLDWEIGHT |
The property to specify whether the font is bold.
|
static java.lang.String |
PROPERTY_FONT_CHARSET |
The property to specify the charset used by the font.
|
static java.lang.String |
PROPERTY_FONT_COLOR |
The property to specify the font color.
|
static java.lang.String |
PROPERTY_FONT_HEIGHT_IN_POINTS |
The property to specify the font height in points.
|
static java.lang.String |
PROPERTY_FONT_ITALIC |
The property to specify whether the font is italic.
|
static java.lang.String |
PROPERTY_FONT_NAME |
The property to specify the font name.
|
static java.lang.String |
PROPERTY_FONT_STRIKEOUT |
The property to specify whether the font is strikeout.
|
static java.lang.String |
PROPERTY_FONT_TYPE_OFFSET |
The property to specify whether the font type is offset, and if it is,
whether it's superscript or subscript.
|
static java.lang.String |
PROPERTY_FONT_UNDERLINE |
The property to specify how the font text is underlined.
|
static java.lang.String |
PROPERTY_HIDDEN |
The property to specify the "hidden" property.
|
static java.lang.String |
PROPERTY_INDENTION |
The property to specify the number of characters that the text is
indented.
|
static java.lang.String |
PROPERTY_LEFT_BORDER_COLOR |
The property to specify the color of the left border.
|
static java.lang.String |
PROPERTY_LOCKED |
The property to specify the "locked" property.
|
static java.lang.String |
PROPERTY_RIGHT_BORDER_COLOR |
The property to specify the color of the right border.
|
static java.lang.String |
PROPERTY_ROTATION |
The property to specify the number of degrees that the text is rotated,
from -90 to +90.
|
static java.lang.String |
PROPERTY_ROW_HEIGHT_IN_POINTS |
The property to specify the height of the row in points.
|
static java.lang.String |
PROPERTY_TOP_BORDER_COLOR |
The property to specify the color of the top border.
|
static java.lang.String |
PROPERTY_VERTICAL_ALIGNMENT |
The property to specify the vertical alignment of the text.
|
static java.lang.String |
PROPERTY_WRAP_TEXT |
The property to specify whether long text values are wrapped to the next
physical line within the cell.
|
static java.lang.String |
ROTATION_STACKED |
Specify this value of rotation to use to produce vertically
|
Constructor | Description |
---|---|
StyleParser() |
Create a
StyleParser . |
StyleParser(java.lang.String cssText) |
Create a
StyleParser object that will parse the given
css text. |
Modifier and Type | Method | Description |
---|---|---|
static void |
addStyle(Style style,
java.lang.String property,
java.lang.String value) |
Depending on the given property, parse the given value and set the
appropriate attribute in the given
Style object. |
java.util.Map<java.lang.String,Style> |
getStyleMap() |
Returns the style map of style names to
Styles . |
void |
parse() |
Parses the CSS text.
|
void |
setCssText(java.lang.String cssText) |
Sets the CSS text to the given CSS text and resets the parser.
|
public static final java.lang.String PROPERTY_ALIGNMENT
Alignment
,
Constant Field Valuespublic static final java.lang.String PROPERTY_BORDER
BorderType
,
Constant Field Valuespublic static final java.lang.String PROPERTY_BORDER_BOTTOM
BorderType
,
Constant Field Valuespublic static final java.lang.String PROPERTY_BORDER_LEFT
BorderType
,
Constant Field Valuespublic static final java.lang.String PROPERTY_BORDER_RIGHT
BorderType
,
Constant Field Valuespublic static final java.lang.String PROPERTY_BORDER_TOP
BorderType
,
Constant Field Valuespublic static final java.lang.String PROPERTY_BORDER_COLOR
ExcelColor
,
Constant Field Valuespublic static final java.lang.String PROPERTY_BOTTOM_BORDER_COLOR
ExcelColor
,
Constant Field Valuespublic static final java.lang.String PROPERTY_LEFT_BORDER_COLOR
ExcelColor
,
Constant Field Valuespublic static final java.lang.String PROPERTY_RIGHT_BORDER_COLOR
ExcelColor
,
Constant Field Valuespublic static final java.lang.String PROPERTY_TOP_BORDER_COLOR
ExcelColor
,
Constant Field Valuespublic static final java.lang.String PROPERTY_COLUMN_WIDTH_IN_CHARS
public static final java.lang.String PROPERTY_DATA_FORMAT
public static final java.lang.String PROPERTY_FILL_BACKGROUND_COLOR
ExcelColor
,
Constant Field Valuespublic static final java.lang.String PROPERTY_FILL_FOREGROUND_COLOR
ExcelColor
,
Constant Field Valuespublic static final java.lang.String PROPERTY_FILL_PATTERN
FillPattern
,
Constant Field Valuespublic static final java.lang.String PROPERTY_HIDDEN
public static final java.lang.String PROPERTY_INDENTION
public static final java.lang.String PROPERTY_LOCKED
public static final java.lang.String PROPERTY_ROTATION
public static final java.lang.String PROPERTY_ROW_HEIGHT_IN_POINTS
public static final java.lang.String PROPERTY_VERTICAL_ALIGNMENT
VerticalAlignment
,
Constant Field Valuespublic static final java.lang.String PROPERTY_WRAP_TEXT
public static final java.lang.String PROPERTY_FONT_BOLDWEIGHT
public static final java.lang.String PROPERTY_FONT_CHARSET
FontCharset
,
Constant Field Valuespublic static final java.lang.String PROPERTY_FONT_COLOR
ExcelColor
,
Constant Field Valuespublic static final java.lang.String PROPERTY_FONT_HEIGHT_IN_POINTS
public static final java.lang.String PROPERTY_FONT_NAME
public static final java.lang.String PROPERTY_FONT_ITALIC
public static final java.lang.String PROPERTY_FONT_STRIKEOUT
public static final java.lang.String PROPERTY_FONT_TYPE_OFFSET
FontTypeOffset
,
Constant Field Valuespublic static final java.lang.String PROPERTY_FONT_UNDERLINE
FontUnderline
,
Constant Field Valuespublic static final java.lang.String ROTATION_STACKED
Specify this value of rotation to use to produce vertically
text.
PROPERTY_ROTATION
,
Constant Field Valuespublic static final short POI_ROTATION_STACKED
POI value of rotation to use to produce vertically
text.
PROPERTY_ROTATION
,
Constant Field Valuespublic StyleParser()
StyleParser
.public StyleParser(java.lang.String cssText)
StyleParser
object that will parse the given
css text.cssText
- The CSS text.public void setCssText(java.lang.String cssText)
cssText
- The new CSS text.public void parse()
public static void addStyle(Style style, java.lang.String property, java.lang.String value)
Style
object.style
- A Style
.property
- A property name, which should be one of the property name
constants defined in this class.value
- The property value, the meaning of which is
property-specific.public java.util.Map<java.lang.String,Style> getStyleMap()
Styles
.Map
of style names to Styles
.Copyright © 2012–2018 Jett Team. All rights reserved.