use of org.apache.poi.ss.usermodel.CellStyle in project poi by apache.
the class FillsAndColors method main.
public static void main(String[] args) throws IOException {
//or new HSSFWorkbook();
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
Row row = sheet.createRow(1);
// Aqua background
CellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
style.setFillPattern(FillPatternType.BIG_SPOTS);
Cell cell = row.createCell(1);
cell.setCellValue(new XSSFRichTextString("X"));
cell.setCellStyle(style);
// Orange "foreground", foreground being the fill foreground not the font color.
style = wb.createCellStyle();
style.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cell = row.createCell(2);
cell.setCellValue(new XSSFRichTextString("X"));
cell.setCellStyle(style);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("fill_colors.xlsx");
wb.write(fileOut);
fileOut.close();
wb.close();
}
use of org.apache.poi.ss.usermodel.CellStyle in project poi by apache.
the class TestCellStyle method test56959.
public void test56959() throws IOException {
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("somesheet");
Row row = sheet.createRow(0);
// Create a new font and alter it.
Font font = wb.createFont();
font.setFontHeightInPoints((short) 24);
font.setFontName("Courier New");
font.setItalic(true);
font.setStrikeout(true);
font.setColor(Font.COLOR_RED);
CellStyle style = wb.createCellStyle();
style.setBorderBottom(BorderStyle.DOTTED);
style.setFont(font);
Cell cell = row.createCell(0);
cell.setCellStyle(style);
cell.setCellValue("testtext");
Cell newCell = row.createCell(1);
newCell.setCellStyle(style);
newCell.setCellValue("2testtext2");
CellStyle newStyle = newCell.getCellStyle();
assertEquals(BorderStyle.DOTTED, newStyle.getBorderBottomEnum());
assertEquals(Font.COLOR_RED, ((HSSFCellStyle) newStyle).getFont(wb).getColor());
// OutputStream out = new FileOutputStream("/tmp/56959.xls");
// try {
// wb.write(out);
// } finally {
// out.close();
// }
}
use of org.apache.poi.ss.usermodel.CellStyle in project poi by apache.
the class TestBugs method bug49524.
/**
* Vertically aligned text
*/
@Test
public void bug49524() throws Exception {
HSSFWorkbook wb1 = openSample("49524.xls");
Sheet s = wb1.getSheetAt(0);
Row r = s.getRow(0);
Cell rotated = r.getCell(0);
Cell normal = r.getCell(1);
// Check the current ones
assertEquals(0, normal.getCellStyle().getRotation());
assertEquals(0xff, rotated.getCellStyle().getRotation());
// Add a new style, also rotated
CellStyle cs = wb1.createCellStyle();
cs.setRotation((short) 0xff);
Cell nc = r.createCell(2);
nc.setCellValue("New Rotated Text");
nc.setCellStyle(cs);
assertEquals(0xff, nc.getCellStyle().getRotation());
// Write out and read back
HSSFWorkbook wb2 = writeOutAndReadBack(wb1);
wb1.close();
// Re-check
s = wb2.getSheetAt(0);
r = s.getRow(0);
rotated = r.getCell(0);
normal = r.getCell(1);
nc = r.getCell(2);
assertEquals(0, normal.getCellStyle().getRotation());
assertEquals(0xff, rotated.getCellStyle().getRotation());
assertEquals(0xff, nc.getCellStyle().getRotation());
wb2.close();
}
use of org.apache.poi.ss.usermodel.CellStyle in project poi by apache.
the class TestBugs method bug49237.
/** Row style information is 12 not 16 bits */
@Test
public void bug49237() throws Exception {
Workbook wb = openSample("49237.xls");
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(0);
CellStyle rstyle = row.getRowStyle();
assertNotNull(rstyle);
assertEquals(BorderStyle.DOUBLE, rstyle.getBorderBottomEnum());
wb.close();
}
use of org.apache.poi.ss.usermodel.CellStyle in project poi by apache.
the class TestXSSFDataFormat method test58778.
/**
* [Bug 58778] Built-in number formats can be overridden with XSSFDataFormat.putFormat(int id, String fmt)
*/
@Test
public void test58778() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook();
Cell cell = wb1.createSheet("bug58778").createRow(0).createCell(0);
cell.setCellValue(5.25);
CellStyle style = wb1.createCellStyle();
XSSFDataFormat dataFormat = wb1.createDataFormat();
short poundFmtIdx = 6;
dataFormat.putFormat(poundFmtIdx, poundFmt);
style.setDataFormat(poundFmtIdx);
cell.setCellStyle(style);
// Cell should appear as "<poundsymbol>5"
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutCloseAndReadBack(wb1);
cell = wb2.getSheet("bug58778").getRow(0).getCell(0);
assertEquals(5.25, cell.getNumericCellValue(), 0);
style = cell.getCellStyle();
assertEquals(poundFmt, style.getDataFormatString());
assertEquals(poundFmtIdx, style.getDataFormat());
// manually check the file to make sure the cell is rendered as "<poundsymbol>5"
// Verified with LibreOffice 4.2.8.2 on 2015-12-28
wb2.close();
wb1.close();
}
Aggregations