赞
踩
一、Java使用Apache POI导出excel
二、Apache POI 操作Excel常用方法
三、Apache poi 拆分单元格并赋值
四、使用easypoi模板方法导出excel
五、Apache poi给excel单元格添加下拉框或数据验证
效果图
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.3.0</version>
</dependency>
<!-- 建议只用start -->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>4.3.0</version>
</dependency>
public static void main(String[] args) {
String s = exportExcel();
System.out.println(s);
}
public static String exportExcel () {
// 文件输出路径
String excelPath = "D:\\桌面\\";
// 模板导出
Map<String, Object> map = new HashMap<String, Object>();
ArrayList<Object> list = new ArrayList<>();
for (int i = 1; i < 5; i++) {
HashMap<String, String> lm = new HashMap<>();
lm.put("name", "姓名" + i);
lm.put("class", "班级" + i);
lm.put("age", "年龄" + i);
list.add(lm);
}
map.put("list", list);
TemplateExportParams params = new TemplateExportParams(
"./xlsx/test.xlsx"); // 模板路径
Workbook workbook = ExcelExportUtil.exportExcel(params, map);
File savefile = new File(excelPath);
if (!savefile.exists()) {
savefile.mkdirs();
}
String path = excelPath + "测试.xlsx"; // 文件输出路径
try {
FileOutputStream fos = new FileOutputStream(path);
workbook.write(fos);
fos.close();
return path;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
效果图
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.3.0</version>
</dependency>
<!-- 建议只用start -->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>4.3.0</version>
</dependency>
public static void main(String[] args) {
String s = exportExcel();
System.out.println(s);
}
public static String exportExcel () {
// 文件输出路径
String excelPath = "D:\\桌面\\";
// 模板导出
Map<String, Object> map = new HashMap<String, Object>();
ArrayList<Object> list = new ArrayList<>();
for (int i = 1; i < 5; i++) {
HashMap<String, String> lm = new HashMap<>();
lm.put("name", "姓名" + i);
lm.put("class", "班级" + i);
lm.put("age", "年龄" + i);
list.add(lm);
}
map.put("list", list);
TemplateExportParams params = new TemplateExportParams(
"./xlsx/test.xlsx"); // 模板路径
params.setColForEach(true);
Workbook workbook = ExcelExportUtil.exportExcel(params, map);
File savefile = new File(excelPath);
if (!savefile.exists()) {
savefile.mkdirs();
}
String path = excelPath + "测试.xlsx"; // 文件输出路径
try {
FileOutputStream fos = new FileOutputStream(path);
workbook.write(fos);
fos.close();
return path;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。