HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet hssfSheet = workbook.createSheet("sheet1");
HSSFRow hssfRow = hssfSheet.createRow(0);
hssfRow.setHeight((short)500);
HSSFCellStyle hssfCellStyle = workbook.createCellStyle();
hssfCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
hssfCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
HSSFFont font = workbook.createFont();
font.setFontHeightInPoints((short) 10);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
hssfCellStyle.setFont(font);
hssfCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
hssfCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
hssfCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
hssfCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
final String[] titles = { "protocol", "", "host", "port","resource"};
HSSFCell hssfCell = null;
for (int i = 0; i < titles.length; i++) {
hssfCell = hssfRow.createCell(i);
hssfCell.setCellValue(titles[i]);
hssfCell.setCellStyle(hssfCellStyle);
}
for (int i = 0; i < content.size(); i++){
Server lic = content.get(i);
hssfRow = hssfSheet.createRow(i+1);
hssfRow.setHeight((short)300);
HSSFCellStyle contentRowStyle = workbook.createCellStyle();
contentRowStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
contentRowStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
font = workbook.createFont();
contentRowStyle.setFont(font);
hssfRow.setRowStyle(contentRowStyle);
hssfRow.createCell(0).setCellValue(lic.getProtocol());
hssfRow.createCell(1).setCellValue(lic.getHost());
hssfRow.createCell(2).setCellValue(lic.getPort());
hssfRow.createCell(3).setCellValue(lic.getResource());
}
final int defaultWidth = 5000;
for (int x = 13; x >= 0; x--){
hssfSheet.setColumnWidth(x, defaultWidth);
}
hssfSheet.setColumnWidth(8, 10000);
try {
workbook.write(outputStream);
outputStream.flush();
outputStream.close();
} catch (IOException e) {
log.error("导出失败");
e.printStackTrace();
}
POI导出Excel
最新推荐文章于 2023-06-14 09:41:37 发布