java excel 边框_java POI设置Excel单元格的边框样式

Workbook wb = new HSSFWorkbook();

Sheet sheet = wb.createSheet("new sheet");

// Create a row and put some cells in it. Rows are 0 based.

Row row = sheet.createRow(1);

// Create a cell and put a value in it.

Cell cell = row.createCell(1);

cell.setCellValue(4);

// Style the cell with borders all around.

CellStyle style = wb.createCellStyle();

style.setBorderBottom(CellStyle.BORDER_THIN);

style.setBottomBorderColor(IndexedColors.BLACK.getIndex());

style.setBorderLeft(CellStyle.BORDER_THIN);

style.setLeftBorderColor(IndexedColors.GREEN.getIndex());

style.setBorderRight(CellStyle.BORDER_THIN);

style.setRightBorderColor(IndexedColors.BLUE.getIndex());

style.setBorderTop(CellStyle.BORDER_MEDIUM_DASHED);

style.setTopBorderColor(IndexedColors.BLACK.getIndex());

cell.setCellStyle(style);

// Write the output to a file

FileOutputStream fileOut = new FileOutputStream("E:\\standarcode\\borders.xls");

wb.write(fileOut);

fileOut.close();

结果:

0818b9ca8b590ca3270a3433284dd417.png

你可能感兴趣的:(java,excel,边框)