use of org.apache.poi.xssf.model.StylesTable in project poi by apache.
the class TestXSSFWorkbook method getFontAt.
@Test
public void getFontAt() throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
try {
StylesTable styleSource = workbook.getStylesSource();
short i = 0;
//get default font
Font fontAt = workbook.getFontAt(i);
assertNotNull(fontAt);
//get customized font
XSSFFont customFont = new XSSFFont();
customFont.setItalic(true);
int x = styleSource.putFont(customFont);
fontAt = workbook.getFontAt((short) x);
assertNotNull(fontAt);
} finally {
workbook.close();
}
}
use of org.apache.poi.xssf.model.StylesTable in project poi by apache.
the class TestColumnHelper method testGetSetColDefaultStyle.
@Test
public void testGetSetColDefaultStyle() throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
CTWorksheet ctWorksheet = sheet.getCTWorksheet();
ColumnHelper columnHelper = sheet.getColumnHelper();
// POI column 3, OOXML column 4
CTCol col = columnHelper.getOrCreateColumn1Based(4, false);
assertNotNull(col);
assertNotNull(columnHelper.getColumn(3, false));
columnHelper.setColDefaultStyle(3, 2);
assertEquals(2, columnHelper.getColDefaultStyle(3));
assertEquals(-1, columnHelper.getColDefaultStyle(4));
StylesTable stylesTable = workbook.getStylesSource();
CTXf cellXf = CTXf.Factory.newInstance();
cellXf.setFontId(0);
cellXf.setFillId(0);
cellXf.setBorderId(0);
cellXf.setNumFmtId(0);
cellXf.setXfId(0);
stylesTable.putCellXf(cellXf);
CTCol col_2 = ctWorksheet.getColsArray(0).addNewCol();
col_2.setMin(10);
col_2.setMax(12);
col_2.setStyle(1);
assertEquals(1, columnHelper.getColDefaultStyle(11));
XSSFCellStyle cellStyle = new XSSFCellStyle(0, 0, stylesTable, null);
columnHelper.setColDefaultStyle(11, cellStyle);
assertEquals(0, col_2.getStyle());
assertEquals(1, columnHelper.getColDefaultStyle(10));
workbook.close();
}
use of org.apache.poi.xssf.model.StylesTable in project poi by apache.
the class TestXSSFReader method test58747.
/**
* NPE from XSSFReader$SheetIterator.<init> on XLSX files generated by
* the openpyxl library
*/
public void test58747() throws Exception {
OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("58747.xlsx");
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(pkg);
assertNotNull(strings);
XSSFReader reader = new XSSFReader(pkg);
StylesTable styles = reader.getStylesTable();
assertNotNull(styles);
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) reader.getSheetsData();
assertEquals(true, iter.hasNext());
iter.next();
assertEquals(false, iter.hasNext());
assertEquals("Orders", iter.getSheetName());
pkg.close();
}
use of org.apache.poi.xssf.model.StylesTable in project poi by apache.
the class TestXSSFCellStyle method testGetFillForegroundColor.
@Test
public void testGetFillForegroundColor() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook();
StylesTable styles = wb.getStylesSource();
assertEquals(1, wb.getNumCellStyles());
assertEquals(2, styles.getFills().size());
XSSFCellStyle defaultStyle = wb.getCellStyleAt((short) 0);
assertEquals(IndexedColors.AUTOMATIC.getIndex(), defaultStyle.getFillForegroundColor());
assertEquals(null, defaultStyle.getFillForegroundXSSFColor());
assertEquals(FillPatternType.NO_FILL, defaultStyle.getFillPatternEnum());
assertEquals(CellStyle.NO_FILL, defaultStyle.getFillPattern());
XSSFCellStyle customStyle = wb.createCellStyle();
customStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
assertEquals(FillPatternType.SOLID_FOREGROUND, customStyle.getFillPatternEnum());
assertEquals(CellStyle.SOLID_FOREGROUND, customStyle.getFillPattern());
assertEquals(3, styles.getFills().size());
customStyle.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
assertEquals(IndexedColors.BRIGHT_GREEN.getIndex(), customStyle.getFillForegroundColor());
assertEquals(4, styles.getFills().size());
for (int i = 0; i < 3; i++) {
XSSFCellStyle style = wb.createCellStyle();
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
assertEquals(FillPatternType.SOLID_FOREGROUND, style.getFillPatternEnum());
assertEquals(CellStyle.SOLID_FOREGROUND, style.getFillPattern());
assertEquals(4, styles.getFills().size());
style.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
assertEquals(IndexedColors.BRIGHT_GREEN.getIndex(), style.getFillForegroundColor());
assertEquals(4, styles.getFills().size());
}
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
wb.close();
}
use of org.apache.poi.xssf.model.StylesTable in project poi by apache.
the class TestXSSFCellStyle method testBug52348.
/**
* Avoid ArrayIndexOutOfBoundsException when creating cell style
* in a workbook that has an empty xf table.
*/
@Test
public void testBug52348() throws IOException {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("52348.xlsx");
StylesTable st = workbook.getStylesSource();
assertEquals(0, st._getStyleXfsSize());
// no exception at this point
XSSFCellStyle style = workbook.createCellStyle();
assertNull(style.getStyleXf());
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(workbook);
assertNotNull(wb2);
wb2.close();
workbook.close();
}
Aggregations