这里的filename是目录的名称,XSSFWorkbook对应的是2007版本的,也可以将其换成2003版本HSSFWorkbook。
具体流程是首先创建一个excel对象,然后可以创建sheet,创建row以及cell,其中也可以设置颜色,样式等信息,最后通过new 文件输出流,将其输出到传入的目录下
/**
-
创建空白的excel文件
-
@param filename
-
@throws IOException
*/
public static void CreateBlankExcel(String filename) throws IOException {// Create Blank workbook
XSSFWorkbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet();
XSSFCellStyle cellStyle = workbook.createCellStyle();
XSSFFont font = workbook.createFont();
font.setColor(Font.COLOR_RED);
cellStyle.setFont(font);
Row row = sheet.createRow(0);
Cell cell0 = row.createCell(0);
cell0.setCellValue(“序号”);
Cell cell1 = row.createCell(1);
cell1.setCellValue(“组织*”);
Cell cell2 = row.createCell(2);
cell2.setCellValue(“111*”);
Cell cell3 = row.createCell(3);
cell3.setCellValue(“222*”);
Cell cell4 = row.createCell(4);
cell4.setCellValue(“333*”);
Cell cell5 = row.createCell(5);
cell5.setCellValue(“收方户名*”);
Cell cell6 = row.createCell(6);
cell6.setCellValue(“444*”);
Cell cell7 = row.createCell(7);
cell7.setCellValue(“金额*”);
Cell cell8 = row.createCell(8);
cell8.setCellValue(“555*”);
Cell cell9 = row.createCell(9);
cell9.setCellValue(“666*”);
Cell cell10 = row.createCell(10);
cell10.setCellValue(“777”);
Cell cell11 = row.createCell(11);
cell11.setCellValue(“5”);
Cell cell12 = row.createCell(12);
cell12.setCellValue(“5”);
Cell cell13 = row.createCell(13);
cell13.setCellValue(“5”);
Cell cell14 = row.createCell(14);
cell14.setCellValue(“5”);
Cell cell15 = row.createCell(15);
cell15.setCellValue(“用途”);
Cell cell16 = row.createCell(16);
cell16.setCellValue(“5”);
Cell cell17 = row.createCell(17);
cell17.setCellValue(“5”);
Cell cell18 = row.createCell(18);
cell18.setCellValue(“5”);
Cell cell19 = row.createCell(19);
cell19.setCellValue(“5”);
Cell cell20 = row.createCell(20);
cell20.setCellValue(“5”);
Cell cell21 = row.createCell(21);
cell21.setCellValue(“5”);
// Create file system using specific name
FileOutputStream out = new FileOutputStream(new File(filename));
// write operation workbook using file out object
workbook.write(out);
out.close();
}