Java生成Excel文档

HSSFWorkbook workBook = new HSSFWorkbook();
HSSFSheet sheet = workBook.createSheet();
HSSFRow row = sheet.createRow(0);
//样式
			
HSSFFont workFont = workBook.createFont();
workFont.setFontName("微软雅黑");
workFont.setFontHeightInPoints((short)14);
workFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
			
HSSFCellStyle cellStyle = workBook.createCellStyle();
cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cellStyle.setFont(workFont);
		
HSSFCell cell = row.createCell(0);
cell.setCellValue("001");
cell.setCellStyle(cellStyle);
			
cell = row.createCell(1);
cell.setCellValue("华家乐");
cell.setCellStyle(cellStyle);

			
cell = row.createCell(2);
cell.setCellValue("1981-08-17");
cell.setCellStyle(cellStyle);
			
workBook.setSheetName(0, "新建工作薄");

FileOutputStream fos = new FileOutputStream("d:/test.xls");
workBook.write(fos);
fos.flush();
fos.close();

你可能感兴趣的:(java,工作,Excel)