Excel2007以上版本导出Excel,并分成多个sheet
使用Apache POI导出Excel(.xlsx)
Excel <=2003 数据限制,行(65536)列(256)
Excel =2007 数据限制,行(1048576)列(16384)
Apache POI官方网站
Apache POI使用详解
package exportexcel;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class BuildXLSX_V2 {
@SuppressWarnings({ "resource", "unchecked" })
public static void main(String[] args) throws IOException {
LinkedHashMap titleMap = new LinkedHashMap();
titleMap.put("rowId", "序号");
titleMap.put("stuName", "姓名");
titleMap.put("stuNum", "学号");
titleMap.put("stuGender", "性别");
titleMap.put("stuAdmission", "入学日期");
//需要导出的数据
List
}
StudentBean 文件
package exportexcel;
import java.util.Date;
public class StudentBean {
/**学号*/
private int rowId;
/**姓名*/
private String stuName;
/**学号*/
private String stuNum;
/**性别*/
private String stuGender;
/**入学日期*/
private Date stuAdmission;
/**总成绩*/
private int stuCountScore;
/**备注*/
String remark;
public int getRowId() {
return rowId;
}
public void setRowId(int rowId) {
this.rowId = rowId;
}
public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public String getStuNum() {
return stuNum;
}
public void setStuNum(String stuNum) {
this.stuNum = stuNum;
}
public String getStuGender() {
return stuGender;
}
public void setStuGender(String stuGender) {
this.stuGender = stuGender;
}
public Date getStuAdmission() {
return stuAdmission;
}
public void setStuAdmission(Date stuAdmission) {
this.stuAdmission = stuAdmission;
}
public int getStuCountScore() {
return stuCountScore;
}
public void setStuCountScore(int stuCountScore) {
this.stuCountScore = stuCountScore;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
需要的jar包
poi-3.15.jar
poi-ooxml-3.15.jar
poi-ooxml-schemas-3.15.jar
commons-collections4-4.1.jar
xmlbeans-2.3.0.jar