1.jar的依赖
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
2.方法
public void exportUser2(HttpServletResponse response,List<UserPojo> pojo) throws Exception{
response.setContentType("application/x-execl");response.setHeader("Content-Disposition", "attachment;filename="+new String("用户列表.xlsx".getBytes(),"ISO-8859-1"));
ServletOutputStream out = response.getOutputStream();
//创建工作薄
XSSFWorkbook workbook = new XSSFWorkbook();
//新建工作表
XSSFSheet sheet = workbook.createSheet("用户信息");
//合并单元格
CellRangeAddress cellRangeAddress = new CellRangeAddress(0, 2, 0, 3);//括号中分别表示(起始行号,终止行号, 起始列号,终止列号)
sheet.addMergedRegion(cellRangeAddress);
//设置合并单元格的内容
//创建行