public class StylesTable extends POIXMLDocumentPart implements Styles
POIXMLDocumentPart.RelationPart
Modifier and Type | Field and Description |
---|---|
static int |
FIRST_CUSTOM_STYLE_ID
The first style id available for use as a custom style
|
Constructor and Description |
---|
StylesTable()
Create a new, empty StylesTable
|
StylesTable(PackagePart part) |
Modifier and Type | Method and Description |
---|---|
int |
_getDXfsSize() |
int |
_getStyleXfsSize()
For unit testing only
|
protected void |
commit()
Save the content in the underlying package part.
|
XSSFCellStyle |
createCellStyle()
Create a cell style in this style table.
|
void |
ensureThemesTable()
If there isn't currently a
ThemesTable for the
current Workbook, then creates one and sets it up. |
XSSFFont |
findFont(boolean bold,
Color color,
short fontHeight,
java.lang.String name,
boolean italic,
boolean strikeout,
short typeOffset,
byte underline)
Finds a font that matches the one with the supplied attributes,
where color is the actual Color-value, not the indexed color
|
XSSFFont |
findFont(boolean bold,
short color,
short fontHeight,
java.lang.String name,
boolean italic,
boolean strikeout,
short typeOffset,
byte underline)
Finds a font that matches the one with the supplied attributes,
where color is the indexed-value, not the actual color.
|
XSSFCellBorder |
getBorderAt(int idx) |
java.util.List<XSSFCellBorder> |
getBorders() |
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf |
getCellStyleXfAt(int idx) |
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf |
getCellXfAt(int idx) |
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet |
getCTStylesheet()
For unit testing only!
|
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxf |
getDxfAt(int idx) |
TableStyle |
getExplicitTableStyle(java.lang.String name)
NOTE: this only returns explicitly defined styles
|
java.util.Set<java.lang.String> |
getExplicitTableStyleNames() |
XSSFCellFill |
getFillAt(int idx) |
java.util.List<XSSFCellFill> |
getFills() |
XSSFFont |
getFontAt(int idx) |
java.util.List<XSSFFont> |
getFonts() |
IndexedColorMap |
getIndexedColors() |
int |
getMaxNumberOfDataFormats()
Get the upper limit on the number of data formats that has been set for the style table.
|
java.lang.String |
getNumberFormatAt(short fmtId)
Get number format string given its id
|
java.util.Map<java.lang.Short,java.lang.String> |
getNumberFormats() |
int |
getNumCellStyles()
get the size of cell styles
|
int |
getNumDataFormats() |
XSSFCellStyle |
getStyleAt(int idx) |
TableStyle |
getTableStyle(java.lang.String name) |
ThemesTable |
getTheme()
Get the current Workbook's theme table, or null if the
Workbook lacks any themes.
|
int |
putBorder(XSSFCellBorder border)
Adds a border to the border style table if it isn't already in the style table
Does nothing if border is already in borders style table
|
int |
putCellStyleXf(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf cellStyleXf)
Adds a cell style to the styles table.
|
int |
putCellXf(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf cellXf)
Adds a cell to the styles table.
|
int |
putDxf(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxf dxf)
Adds a Dxf to the style table
Does not check for duplicates.
|
int |
putFill(XSSFCellFill fill)
Adds a fill to the fill style table if it isn't already in the style table
Does nothing if fill is already in fill style table
|
int |
putFont(XSSFFont font)
Records the given font in the font table.
|
int |
putFont(XSSFFont font,
boolean forceRegistration)
Records the given font in the font table.
|
void |
putNumberFormat(short index,
java.lang.String fmt)
Add a number format with a specific ID into the numberFormats map.
|
int |
putNumberFormat(java.lang.String fmt)
Puts
fmt in the numberFormats map if the format is not
already in the the number format style table. |
int |
putStyle(XSSFCellStyle style) |
void |
readFrom(java.io.InputStream is)
Read this shared styles table from an XML file.
|
boolean |
removeNumberFormat(short index)
Remove a number format from the style table if it exists.
|
boolean |
removeNumberFormat(java.lang.String fmt)
Remove a number format from the style table if it exists
All cell styles with this number format will be modified to use the default number format
|
protected void |
replaceCellStyleXfAt(int idx,
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf cellStyleXf) |
void |
replaceCellXfAt(int idx,
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf cellXf) |
void |
setMaxNumberOfDataFormats(int num)
Changes the maximum number of data formats that may be in a style table
|
void |
setTheme(ThemesTable theme) |
void |
setWorkbook(XSSFWorkbook wb) |
void |
writeTo(java.io.OutputStream out)
Write this table out as XML.
|
_invokeOnDocumentRead, addRelation, createRelationship, createRelationship, createRelationship, getNextPartNumber, getPackagePart, getParent, getRelationById, getRelationId, getRelationPartById, getRelationParts, getRelations, getTargetPart, isCommitted, onDocumentCreate, onDocumentRead, onDocumentRemove, onSave, prepareForCommit, read, rebase, removeRelation, removeRelation, removeRelation, setCommitted, toString
public static final int FIRST_CUSTOM_STYLE_ID
public StylesTable()
public StylesTable(PackagePart part) throws java.io.IOException
java.io.IOException
public void setMaxNumberOfDataFormats(int num)
num
- the upper limit on number of data formats in the styles table when adding new data formatsjava.lang.IllegalArgumentException
- if num
< 0java.lang.IllegalStateException
- if num
< current number of data formats in the style table.
Data formats must be explicitly removed before the limit can be decreased.public int getMaxNumberOfDataFormats()
getNumDataFormats()
.public void setWorkbook(XSSFWorkbook wb)
public ThemesTable getTheme()
Use ensureThemesTable()
to have a themes table
created if needed
public void setTheme(ThemesTable theme)
public void ensureThemesTable()
ThemesTable
for the
current Workbook, then creates one and sets it up.
After this, calls to getTheme()
won't give nullpublic void readFrom(java.io.InputStream is) throws java.io.IOException
is
- The input stream containing the XML document.java.io.IOException
- if an error occurs while reading.public java.lang.String getNumberFormatAt(short fmtId)
getNumberFormatAt
in interface Styles
fmtId
- number format idpublic int putNumberFormat(java.lang.String fmt)
fmt
in the numberFormats map if the format is not
already in the the number format style table.
Does nothing if fmt
is already in number format style table.putNumberFormat
in interface Styles
fmt
- the number format to add to number format style tablefmt
in the number format style tablejava.lang.IllegalStateException
- if adding the number format to the styles table
would exceed the MAXIMUM_NUMBER_OF_DATA_FORMATS
allowed.public void putNumberFormat(short index, java.lang.String fmt)
fmt
This may be used to override built-in number formats.putNumberFormat
in interface Styles
index
- the number format IDfmt
- the number format codepublic boolean removeNumberFormat(short index)
removeNumberFormat
in interface Styles
index
- the number format id to removepublic boolean removeNumberFormat(java.lang.String fmt)
removeNumberFormat
in interface Styles
fmt
- the number format to removepublic int putFont(XSSFFont font, boolean forceRegistration)
XSSFFont.registerTo(StylesTable)
public int putFont(XSSFFont font)
Styles
public XSSFCellStyle getStyleAt(int idx)
getStyleAt
in interface Styles
idx
- style indexpublic int putStyle(XSSFCellStyle style)
public XSSFCellBorder getBorderAt(int idx)
getBorderAt
in interface Styles
public int putBorder(XSSFCellBorder border)
public XSSFCellFill getFillAt(int idx)
public java.util.List<XSSFCellBorder> getBorders()
public java.util.List<XSSFCellFill> getFills()
public java.util.List<XSSFFont> getFonts()
public java.util.Map<java.lang.Short,java.lang.String> getNumberFormats()
public int putFill(XSSFCellFill fill)
@Internal public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf getCellXfAt(int idx)
@Internal public int putCellXf(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf cellXf)
cellXf
- the cell to add to the styles table@Internal public void replaceCellXfAt(int idx, org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf cellXf)
@Internal public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf getCellStyleXfAt(int idx)
@Internal public int putCellStyleXf(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf cellStyleXf)
cellStyleXf
- the cell style to add to the styles table@Internal protected void replaceCellStyleXfAt(int idx, org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf cellStyleXf)
public int getNumCellStyles()
getNumCellStyles
in interface Styles
public int getNumDataFormats()
getNumDataFormats
in interface Styles
@Internal public int _getStyleXfsSize()
@Internal public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet getCTStylesheet()
@Internal public int _getDXfsSize()
public void writeTo(java.io.OutputStream out) throws java.io.IOException
out
- The stream to write to.java.io.IOException
- if an error occurs while writing.protected void commit() throws java.io.IOException
POIXMLDocumentPart
Sub-classes should override and add logic to marshal the "model" into Ooxml4J.
For example, the code saving a generic XML entry may look as follows:
protected void commit() throws IOException { PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); XmlObject bean = getXmlBean(); //the "model" which holds changes in memory bean.save(out, DEFAULT_XML_OPTIONS); out.close(); }
commit
in class POIXMLDocumentPart
java.io.IOException
- a subclass may throw an IOException if the changes can't be committed@Internal public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxf getDxfAt(int idx)
@Internal public int putDxf(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxf dxf)
dxf
- the Dxf to addpublic TableStyle getExplicitTableStyle(java.lang.String name)
name
- of the table stylepublic java.util.Set<java.lang.String> getExplicitTableStyleNames()
public TableStyle getTableStyle(java.lang.String name)
name
- of the table stylepublic XSSFCellStyle createCellStyle()
XSSFWorkbook.createCellStyle()
rather than working with the styles table directly.java.lang.IllegalStateException
- if the maximum number of cell styles has been reached.public XSSFFont findFont(boolean bold, short color, short fontHeight, java.lang.String name, boolean italic, boolean strikeout, short typeOffset, byte underline)
public XSSFFont findFont(boolean bold, Color color, short fontHeight, java.lang.String name, boolean italic, boolean strikeout, short typeOffset, byte underline)
public IndexedColorMap getIndexedColors()
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.