use of org.apache.poi.xssf.model.StylesTable in project poi by apache.
the class XSSFReader method getStylesTable.
/**
* Opens up the Styles Table, parses it, and
* returns a handy object for working with cell styles
*/
public StylesTable getStylesTable() throws IOException, InvalidFormatException {
ArrayList<PackagePart> parts = pkg.getPartsByContentType(XSSFRelation.STYLES.getContentType());
if (parts.size() == 0)
return null;
// Create the Styles Table, and associate the Themes if present
StylesTable styles = new StylesTable(parts.get(0));
parts = pkg.getPartsByContentType(XSSFRelation.THEME.getContentType());
if (parts.size() != 0) {
styles.setTheme(new ThemesTable(parts.get(0)));
}
return styles;
}
use of org.apache.poi.xssf.model.StylesTable in project poi by apache.
the class XSSFConditionalFormattingRule method getDxf.
/*package*/
CTDxf getDxf(boolean create) {
StylesTable styles = _sh.getWorkbook().getStylesSource();
CTDxf dxf = null;
if (styles._getDXfsSize() > 0 && _cfRule.isSetDxfId()) {
int dxfId = (int) _cfRule.getDxfId();
dxf = styles.getDxfAt(dxfId);
}
if (create && dxf == null) {
dxf = CTDxf.Factory.newInstance();
int dxfId = styles.putDxf(dxf);
_cfRule.setDxfId(dxfId - 1);
}
return dxf;
}
use of org.apache.poi.xssf.model.StylesTable in project poi by apache.
the class XLSX2CSV method process.
/**
* Initiates the processing of the XLS workbook file to CSV.
*
* @throws IOException If reading the data from the package fails.
* @throws SAXException if parsing the XML data fails.
*/
public void process() throws IOException, OpenXML4JException, SAXException {
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(this.xlsxPackage);
XSSFReader xssfReader = new XSSFReader(this.xlsxPackage);
StylesTable styles = xssfReader.getStylesTable();
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
int index = 0;
while (iter.hasNext()) {
InputStream stream = iter.next();
String sheetName = iter.getSheetName();
this.output.println();
this.output.println(sheetName + " [index=" + index + "]:");
processSheet(styles, strings, new SheetToCSV(), stream);
stream.close();
++index;
}
}
use of org.apache.poi.xssf.model.StylesTable in project poi by apache.
the class XSSFRow method setRowStyle.
/**
* Applies a whole-row cell styling to the row.
* If the value is null then the style information is removed,
* causing the cell to used the default workbook style.
*/
@Override
public void setRowStyle(CellStyle style) {
if (style == null) {
if (_row.isSetS()) {
_row.unsetS();
_row.unsetCustomFormat();
}
} else {
StylesTable styleSource = getSheet().getWorkbook().getStylesSource();
XSSFCellStyle xStyle = (XSSFCellStyle) style;
xStyle.verifyBelongsToStylesSource(styleSource);
long idx = styleSource.putStyle(xStyle);
_row.setS(idx);
_row.setCustomFormat(true);
}
}
use of org.apache.poi.xssf.model.StylesTable in project poi by apache.
the class TestXSSFCellStyle method setUp.
@Before
public void setUp() {
stylesTable = new StylesTable();
ctStylesheet = stylesTable.getCTStylesheet();
ctBorderA = CTBorder.Factory.newInstance();
XSSFCellBorder borderA = new XSSFCellBorder(ctBorderA);
long borderId = stylesTable.putBorder(borderA);
assertEquals(1, borderId);
XSSFCellBorder borderB = new XSSFCellBorder();
assertEquals(1, stylesTable.putBorder(borderB));
ctFill = CTFill.Factory.newInstance();
XSSFCellFill fill = new XSSFCellFill(ctFill, null);
long fillId = stylesTable.putFill(fill);
assertEquals(2, fillId);
ctFont = CTFont.Factory.newInstance();
XSSFFont font = new XSSFFont(ctFont);
long fontId = stylesTable.putFont(font);
assertEquals(1, fontId);
cellStyleXf = ctStylesheet.addNewCellStyleXfs().addNewXf();
cellStyleXf.setBorderId(1);
cellStyleXf.setFillId(1);
cellStyleXf.setFontId(1);
cellXfs = ctStylesheet.addNewCellXfs();
cellXf = cellXfs.addNewXf();
cellXf.setXfId(1);
cellXf.setBorderId(1);
cellXf.setFillId(1);
cellXf.setFontId(1);
stylesTable.putCellStyleXf(cellStyleXf);
stylesTable.putCellXf(cellXf);
cellStyle = new XSSFCellStyle(1, 1, stylesTable, null);
assertNotNull(stylesTable.getFillAt(1).getCTFill().getPatternFill());
assertEquals(STPatternType.INT_DARK_GRAY, stylesTable.getFillAt(1).getCTFill().getPatternFill().getPatternType().intValue());
}
Aggregations