POI 3.17 Export Style (with 3.9 in different ways)

HSSFWorkbook workbook = new HSSFWorkbook (); // create a workbook
HSSFSheet sheet = workbook.createSheet ( "Test" ); // create SHEET page
HSSFRow row = sheet.createRow (0); // create a row, starting from 0
HSSFCell cell = row.createCell (0); // create columns, starting from 0
cell.setCellValue ( "name");

Setting styles

HSSFCellStyle style = workbook.createCellStyle();

Add borders

style.setBorderBottom (BorderStyle.THIN); // bottom border
style.setBorderLeft (BorderStyle.THIN); // left border
style.setBorderRight (BorderStyle.THIN); // right border
style.setBorderTop (BorderStyle.THIN); // on the border

Center

style.setAlignment (HorizontalAlignment.CENTER); // horizontally centered
style.setVerticalAlignment (VerticalAlignment.CENTER); // vertically centered

Set the font

Font = workbook.createFont HSSFFont ();
font.setFontName ( "Chinese Xingkai"); // set the font name
font.setFontHeightInPoints ((short) 28); // set the font size
font.setItalic (false); // set whether italics
font.setBold (true); // settings are bold
font.setColor (IndexedColors.RED.index); // set the font color
style.setFont (font);

Set Background

style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setFillForegroundColor(IndexedColors.YELLOW.index);

Set Width and Height

row.setHeightInPoints (30); // set the row height
sheet.setColumnWidth (0, 20 * 256) ; // set the width of a column

Rendering Cells

cell.setCellStyle(style);

Guess you like

Origin www.cnblogs.com/123-shen/p/11284563.html