import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
public static void main(String[] args) {
//创建workBook
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(500);
//创建sheet
Sheet sheet = sxssfWorkbook.createSheet("Personal introduction");
//创建excle标题
Row titleRow = sheet.createRow(0);
titleRow.createCell(0).setCellValue("姓名");
titleRow.createCell(1).setCellValue("性别");
titleRow.createCell(2).setCellValue("年龄");
titleRow.createCell(3).setCellValue("身高");
titleRow.createCell(4).setCellValue("外貌");
//创建excle数据
for (int i = 0; i < 3; i++) {
Row valueRow = sheet.createRow(i + 1);
valueRow.createCell(0).setCellValue("Zhang Mengchao");
valueRow.createCell(1).setCellValue("boy");
valueRow.createCell(2).setCellValue("twenty-two");
valueRow.createCell(3).setCellValue("One meter eight");
valueRow.createCell(4).setCellValue("handsome");
}
BufferedOutputStream bos = null;
try {
sxssfWorkbook.write(
bos = new BufferedOutputStream(
new FileOutputStream("E:\\app\\excle.xlsx")));
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Java导出Excle数据
于 2023-01-14 17:33:57 首次发布