首先,Download jxls 的 jar包。官网:http://jxls.sourceforge.net/
加载:jxls-core.jar,如果你有读取excel操作,再加载 jxls-reader.jar.
导入下面的jar包。
jxls-core-1.0-RC-1.jar
commons-collections-3.2.1.jar
commons-jexl-2.0.1.jar
poi-scratchpad-3.7-20101029.jar
poi-3.7-20101029.jar
poi-ooxml-3.7-20101029.jar
poi-ooxml-schemas-3.7-20101029.jar
commons-beanutils-1.8.0.jar
commons-logging-1.1.1.jar
commons-logging-1.1.1-sources.jar
commons-digester-2.1-sources.jar
commons-digester-2.1.jar
xmlbeans-qname.jar
xmlpublic.jar
dom4j-1.6.1.jar
xbean_xpath.jar
jsr173_1.0_api.jar
resolver.jar
xbean.jar
jxls的测试类:
public static void main(String args []) throws ParsePropertyException, InvalidFormatException, IOException{
String templateFileName = "D:\\test-template.xls";//文件格式见附件
String destFileName = "D:\\test-write.xls";
String title = "Excle DownLoad Test";
List<Person> personList = new ArrayList<Person>();
for(int i=0;i<10;i++){
Person person = new Person();
person.setName("person " + i);
personList.add(person);
}
List<Student> studentList = new ArrayList<Student>();
for(int i=0;i<10;i++){
Student student = new Student();
Student.setName("student " + i);
studentList.add(student);
}
List<Area> areaList = new ArrayList<Area>();
for(int i=0;i<10;i++){
Area area = new Area();
area.setAreaId("areaId " + i);
List<String> areaName = new ArrayList<String>();
for(int j=0;j<10;j++){
areaName.add("areaName " + i);
}
area.setAreaName(areaName);
areaList.add(area);
}
Map<String,Object> beans = new HashMap<String,Object>();
beans.put("personList", personList);
beans.put("studentList", studentList);
beans.put("areaList", areaList);
beans.put("title", title);
XLSTransformer transformer = new XLSTransformer();
transformer.transformXLS(templateFileName, beans, destFileName);
}
加载:jxls-core.jar,如果你有读取excel操作,再加载 jxls-reader.jar.
导入下面的jar包。
jxls-core-1.0-RC-1.jar
commons-collections-3.2.1.jar
commons-jexl-2.0.1.jar
poi-scratchpad-3.7-20101029.jar
poi-3.7-20101029.jar
poi-ooxml-3.7-20101029.jar
poi-ooxml-schemas-3.7-20101029.jar
commons-beanutils-1.8.0.jar
commons-logging-1.1.1.jar
commons-logging-1.1.1-sources.jar
commons-digester-2.1-sources.jar
commons-digester-2.1.jar
xmlbeans-qname.jar
xmlpublic.jar
dom4j-1.6.1.jar
xbean_xpath.jar
jsr173_1.0_api.jar
resolver.jar
xbean.jar
jxls的测试类:
public static void main(String args []) throws ParsePropertyException, InvalidFormatException, IOException{
String templateFileName = "D:\\test-template.xls";//文件格式见附件
String destFileName = "D:\\test-write.xls";
String title = "Excle DownLoad Test";
List<Person> personList = new ArrayList<Person>();
for(int i=0;i<10;i++){
Person person = new Person();
person.setName("person " + i);
personList.add(person);
}
List<Student> studentList = new ArrayList<Student>();
for(int i=0;i<10;i++){
Student student = new Student();
Student.setName("student " + i);
studentList.add(student);
}
List<Area> areaList = new ArrayList<Area>();
for(int i=0;i<10;i++){
Area area = new Area();
area.setAreaId("areaId " + i);
List<String> areaName = new ArrayList<String>();
for(int j=0;j<10;j++){
areaName.add("areaName " + i);
}
area.setAreaName(areaName);
areaList.add(area);
}
Map<String,Object> beans = new HashMap<String,Object>();
beans.put("personList", personList);
beans.put("studentList", studentList);
beans.put("areaList", areaList);
beans.put("title", title);
XLSTransformer transformer = new XLSTransformer();
transformer.transformXLS(templateFileName, beans, destFileName);
}