前言
实现Excel与数据库之间批量数据的导入导出
实现步骤
1.导入pom依赖
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.0.0</version>
</dependency>
2.后端代码
/*
导出全部的数据到excel
*/
@RequestMapping("/exceExport")
public void excelExport(HttpServletResponse response) {
//1.创建数据
List<Merch> merchs = merchService.findMerchs();
//2.创建数据表格
//2.1创建excel 写到excel中
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("商品信息统计");
//2.2创建第一行
HSSFRow row = sheet.createRow(0);
HSSFCell cell0 = row.createCell(0);
HSSFCell cell1 = row.createCell(1);
HSSFCell cell2 = row.createCell(2);
HSSFCell cell3 = row.createCell(3);
HSSFCell cell4 = row.createCell(4);
HSSFCell cell5 = row.createCell(5);
HSSFCell cell6 = row.createCell(6);
cell0.setCellValue("序号");
cell1