jimureport使用过程中“踩坑”记录
一、积木存在无法识别特殊字符
如果存在特殊字符的情况可以使用下面的代码替换掉所有的特殊字符
private String removeJimu(String name) {
return name.replaceAll("[^a-zA-Z0-9]", "");
}
二、积木中的pdf生成模块现在并不支持
一般这个时候会直接使用excel2pdf工具,代码如下:
String coaPdfUrl =
fileService.upload(PdfUtil.*excel2pdf*(url, url.getPath().substring(url.getPath().lastIndexOf('/') + 1) + ".pdf"));
注意excel2pdf中存在是否支持分页的情况,一般都需要支持
// 参数true把内容放在一张PDF页面上
pdfSaveOptions.setOnePagePerSheet(false);
三、积木中报错功能会导致查不到值
积木数据采集接口如果报错则不会返回值,所以一般是不需要值的。
四、循环体删除后也需要删除不需要的空白字段
这个会导致excel会持续输出
五、积木的excel接口
public String coaNewExport(String token, ReportProductConfig reportProductConfig) {
// 查询模板id
String reportConfigId = reportProductConfig.getReportConfigId();
if (CommonUtil.isEmpty(reportConfigId)) {
throw new ApiException("模板id不能为空");
}
ReportConfig reportConfig = reportConfigService.getById(reportConfigId);
String jimuReportId = reportConfig.getJimuReportId();
// 上传值
JSONObject var7 = new JSONObject();
var7.put("productBatchNum", reportProductConfig.getProductBatchNum());
var7.put("customerProductCode", reportProductConfig.getCustomerProductCode());
var7.put("cylinderNum", reportProductConfig.getCylinderNum());
var7.put("productId", reportProductConfig.getProductId());
// 调用积木报表
Map var11 = this.exportExcel.exportExcel(jimuReportId, var7, null, (Boolean) null);
// 生成excel表
SXSSFWorkbook var14 = (SXSSFWorkbook) var11.get("workbook");
ByteArrayOutputStream var15 = new ByteArrayOutputStream();
File toFile = new File(reportProductConfig.getProductName() + ".xlsx");
try {
var14.write(var15);
String var17 = Base64Utils.encodeToString(var15.toByteArray());
//转换成byte
byte[] buffer = Base64Utils.decodeFromString(var17);
toFile = bytesToFile(buffer, toFile);
FileInputStream fileInputStream = new FileInputStream(toFile);
String uploadFile = fileService.upload(new MockMultipartFile("copycoaMerge", "coa.xlsx", ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream));
toFile.delete();
return uploadFile;
} catch (Exception e) {
//未生成文件事务回滚
}
return null;
}