添加依赖:
<!-- POI -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
代码:
package com.zp.demoes.controller;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;
@Controller
@RequestMapping("export")
public class ExportController {
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@RequestMapping("exportXls")
public void export(HttpServletResponse response){
List<Map<String,Object>> mapList = new ArrayList<>();
Map<String,Object> map = new HashMap<>();
map.put("name","张三");
map.put("mobile","13523568974");
map.put("sex","男");
map.put("age",19);
map.put("hobby","篮球、羽毛球、兵乓球、足球、滑板、滑旱冰");
mapList.add(map);
map = new HashMap<>();
map.put("name","李四");
map.put("mobile","13452635487");
map.put("sex","男");
map.put("age",23);
map.put("hobby","跑步、跳绳、举重");
mapList.add(map);
map = new HashMap<>();
map.put("name","王五");
map.put("mobile","16674851265");
map.put("sex","男");
map.put("age",18);
map.put("hobby","听音乐、看电影、绘画、写小说");
mapList.add(map);
map = new HashMap<>();
map.put("name","夏天");
map.put("mobile","15574123548");
map.put("sex","女");
map.put("age",22);
map.put("hobby","阅读:读书、读报、看小说");
mapList.add