java创建excel的效果图:
代码块
1. 创建Member类,此类用来创建对象,存储在excel表格中的数据
package com.yu.bai.excel;
import java.util.Date;
//创建一个实体对象,用来存储到excel表中
public class Member {
private Integer code;
private String name;
private Integer age;
private Date birth;
public Member(Integer code, String name, Integer age, Date birth) {
super();
this.code = code;
this.name = name;
this.age = age;
this.birth = birth;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
}
2. 初始化数据,并运行
package com.yu.bai.excel;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 创建excel,写入数据,然后下载到本地
*
* @author baiyu
*
*/
public class DownloadExcel {
public static void main(String[] args) {
Map<String, List<String>> memberMap = getMember();
String[] strArray = excelTitle();
ExcelUtil.createExcel(memberMap, strArray);
}
/**
* 初始化数据,将会被存储到excel表格中
*
* @return
* @throws Exception
*/
private static Map<String, List<String>>