1、建立一个excel模板(demo.xls)如图:
2、编写测试类
public static void main( String args[] ){
public void showhouse(HttpServletRequest request,HttpServletResponse response) throws IOException{
SuiteVo suiteVo = new SuiteVo();
suiteVo.setAddress("shanghai");
suiteVo.setArea(300d);
suiteVo.setFaceDirection(2);
suiteVo.setSuiteNum("33");
suiteVo.setFloorNum(20);
SuiteVo suiteVo1 = new SuiteVo();
suiteVo1.setAddress("shanghai");
suiteVo1.setArea(300d);
suiteVo1.setFaceDirection(2);
suiteVo1.setSuiteNum("33");
suiteVo1.setFloorNum(20);
List<SuiteVo> details = new ArrayList<>();
details.add(suiteVo);
details.add(suiteVo1);
ExcelUtils.addValue("printDate",new Date());
ExcelUtils.addValue("list", details);
ExcelUtils.addValue("suiteVo",suiteVo);
String config = "demo.xls";
response.reset();
response.setContentType("application/vnd.ms-excel");
try {
ExcelUtils.export(config, response.getOutputStream());
} catch (FileNotFoundException ex) {
System.out.println("文件路径找不到");
} catch (ExcelException ex) {
}
}
3、运行后,得到response.xls文件如下: