excel导出入门示例

// 第一步,创建一个webbook,对应一个Excel文件

XSSFWorkbook wb = new XSSFWorkbook();

// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet

XSSFSheet sheet = wb.createSheet("区县工作小组名单");

// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
for (int i = 0; i < 3; i++) {
XSSFRow row = sheet.createRow((int) i);
for (int j = 0; j < 20; j++) {
XSSFCell cel = row.createCell(j);
if (i == 0 && (j > 2 && j < 5)) {
cel.setCellValue("hello");
} else {
cel.setCellValue("50");
}
}

}
FileOutputStream out = new FileOutputStream(new File("D:\file\a.xlsx"));

wb.write(out);

原文地址:https://www.cnblogs.com/songyunxinQQ529616136/p/6889597.html