package com.jxl.json2excel;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileNameUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.jxls.common.Context;
import org.jxls.util.JxlsHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.nio.charset.StandardCharsets;
@Component
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
//@Bean
public void appRun0() throws Exception {
String currentDir = System.getProperty("user.dir") + File.separator;
String jsonDir = currentDir + "json" + File.separator;
String excelDir = currentDir + "excel" + File.separator;
String templateFile = currentDir + "template" + File.separator + "template.xlsx";
LOGGER.info("工作目录:{}", currentDir);
for (File json : FileUtil.ls(jsonDir)) {
JSONObject jsonObject = JSONUtil.readJSONObject(json, StandardCharsets.UTF_8);
try (BufferedInputStream in = FileUtil.getInputStream(templateFile);
BufferedOutputStream out = FileUtil.getOutputStream(excelDir + FileNameUtil.mainName(json) + "-output.xlsx")) {
Context context = new Context();
// context.putVar("jsonMap", jsonObject.getRaw());
context.putVar("json", jsonObject);
context.putVar("util", new ShowUtil());
JxlsHelper.getInstance().processTemplate(in, out, context);
}
}
}
@Bean
public void appRun1() throws Exception {
String currentDir = System.getProperty("user.dir") + File.separator;
String jsonDir = currentDir + "json" + File.separator;
String excelDir = currentDir + "excel" + File.separator;
String templateFile = currentDir + "template" + File.separator + "模板.xlsx";
LOGGER.info("工作目录:{}", currentDir);
for (File json : FileUtil.ls(jsonDir)) {
JSONArray jsonObject = JSONUtil.readJSONArray(json, StandardCharsets.UTF_8);
try (BufferedInputStream in = FileUtil.getInputStream(templateFile);
BufferedOutputStream out = FileUtil.getOutputStream(excelDir + FileNameUtil.mainName(json) + "-output.xlsx")) {
Context context = new Context();
// context.putVar("jsonMap", jsonObject.getRaw());
context.putVar("json", jsonObject);
context.putVar("util", new ExportUtil());
JxlsHelper.getInstance().processTemplate(in, out, context);
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
json2excel.zip (43个子文件)
json2excel
pom.xml 3KB
template
template.xlsx 27KB
模板.xlsx 12KB
bak
物模型_angle_child.json 4KB
物模型_pull_child.json 2KB
物模型_oupushi_audio.json 2KB
物模型_lrk_hoist.json 5KB
物模型_rk_environment.json 8KB
物模型_pull_angle.json 171B
物模型_modelTest.json 1KB
物模型_aisft_position_helmet.json 2KB
物模型_lrk_tower.json 4KB
物模型_lrk_highformwork.json 5KB
物模型_safety_belt.json 2KB
物模型_gas_monitor.json 7KB
物模型_switch_general.json 3KB
物模型_usr_gateway_io.json 5KB
物模型_人脸门禁.json 12KB
物模型_dahua_gate.json 9KB
物模型_无尘化环监.json 6KB
物模型_alean_efence_cloud.json 3KB
物模型_sewage_monitoring.json 1KB
物模型_lrk_report_custom.json 3KB
src
test
java
com
jxl
json2excel
Json2excelApplicationTests.java 227B
main
resources
application.properties 1B
java
com
jxl
json2excel
Json2excelApplication.java 331B
ShowUtil.java 2KB
App.java 3KB
ExportUtil.java 2KB
target
classes
template.xlsx 27KB
application.properties 1B
设备信息-output.xlsx 22KB
设备信息.json 74KB
模板.xlsx 12KB
物联设备信息.xlsx 24KB
com
jxl
json2excel
ExportUtil.class 3KB
Json2excelApplication.class 755B
ShowUtil.class 3KB
App.class 4KB
test-classes
com
jxl
json2excel
Json2excelApplicationTests.class 413B
generated-test-sources
test-annotations
generated-sources
annotations
json
设备信息.json 74KB
excel
设备信息-output.xlsx 22KB
物联设备信息.xlsx 24KB
共 43 条
- 1
资源评论
沫离痕
- 粉丝: 42
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功