poi创建2003与2007还是有点区别的 2003需要一个包 而2007需要好几个包,繁琐
package com.dragon.test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
public class Excel2007Test {
public static void main(String[] args){
String url = "C:/\\Excel2007Test.xlsx";
File file = new File(url);
try { //创建文件流
FileOutputStream fileOutputStream = new FileOutputStream(file);
//创建工作表对象
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(100);
//创建表
Sheet sheet = sxssfWorkbook.createSheet();
//给当前表命名
sxssfWorkbook.setSheetName(0, "口袋里的小龙");
//创建表
Sheet sheet1 = sxssfWorkbook.createSheet();
sxssfWorkbook.setSheetName(1, "猪八戒的小师弟");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("姓名");
Cell cell1 = row.createCell(1);
cell1.setCellValue("年龄");
Cell cell2 = row.createCell(2);
cell2.setCellValue("性别");
Cell cell3 = row.createCell(3);
cell3.setCellValue("家庭住址");
sxssfWorkbook.write(fileOutputStream);
fileOutputStream.close();
sxssfWorkbook.dispose();
System.out.println("生成成功!");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
项目需要的jar文件