Apache poi provide very powerful fetcher for data formation and changing the color, size and font family-
Create workspace and sheet-
XSSFWorkbook workBook = new XSSFWorkbook();
Sheet sheet = workBook.createSheet("My sheet");
Create Font object and set font styling-
Font font = workbook.createFont();
font.setBold( true );
font.setFontHeight( (short) ( 25 * 10 ) );
// set font family
font.setFontName("Courier New");
// set font color
font.setColor( IndexedColors.WHITE.getIndex() );
Create CellStyle object and set alignment of data in cell and set font to the data-
CellStyle cellStyle = new CellStyle();
cellStyle.setFont(font);
// use when you want to wrap text in multipal line
cellStyle.setWrapText(true);Create Row and Cell and set cellStyle for the cell data-
XSSFRow row = sheet.createRow( 1 );
Cell cell = row.createCell(1);
cell.setCellValue("Hello World");
cell.setCellStyle(cellStyle);
Comments
Post a Comment