导出多级合并数据(省市区)
public class Test {
@Data
@ExcelTarget("areaInfo")
@AllArgsConstructor
@NoArgsConstructor
public static class AreaInfo {
@Excel(name = "省", orderNum = "1", width = 25, mergeVertical = true, needMerge = true)
String province;
@Excel(name = "市", orderNum = "2", width = 25, mergeVertical = true, needMerge = true)
String city;
@Excel(name = "区", orderNum = "4", width = 25)
String area;
}
public static void openFile(String path) {
try {
String osName = System.getProperty("os.name");
if (osName != null) {
if (osName.contains("Mac")) {
Runtime.getRuntime().exec("open " + path);
} else if (osName.contains("Windows")) {
Runtime.getRuntime().exec("cmd /c start " + path);
} else {
System.out.println("文件输出目录:" + path);
}
}
} catch (IOException var2) {
var2.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
Workbook workbook = null;
Date start = new Date();
ExportParams params = new ExportParams("大数据测试", "测试");
List list = new ArrayList();
String prov = "";
String city = "";
for (int i = 0; i < 10; i++) {
prov = "省" + i;
for (int i1 = 0; i1 < 10; i1++) {
city = "市" + i1;
for (int i2 = 0; i2 < 10; i2++) {
list.add(new AreaInfo(prov, city, "区" + i2));
}
}
}
System.out.println(JSON.toJSONString(list));
workbook = ExcelExportUtil.exportExcel(params, AreaInfo.class, list);
System.out.println(new Date().getTime() - start.getTime());
String dir = "D:/excel";
File savefile = new File(dir);
if (!savefile.exists()) {
savefile.mkdirs();
}
FileOutputStream fos = new FileOutputStream(dir + "/ExcelExportBigData.bigDataExport.xlsx");
workbook.write(fos);
fos.close();
openFile(dir + "/ExcelExportBigData.bigDataExport.xlsx");
}
}
网友评论