导出数据,支持List<Map>数据导出。 #417
3398502339
started this conversation in
General
Replies: 3 comments
-
Can you describe the problem or error message in detail?
Please refer to this and see if it is helpful to you. 能否具体描述下发现的问题或错误信息?
请参考以上建议看是否对你有所帮助 |
Beta Was this translation helpful? Give feedback.
0 replies
-
![]() ![]() 我是在这里处理的 |
Beta Was this translation helpful? Give feedback.
0 replies
-
![]() ![]() 这个问题我知道,跟源码才知道,参数传错了,你这个可以Map导出 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
有一个业务场景,导入数据的时候,如果类型转换异常了,我们需要把转换错误的数据保存下来,并写到excel返回给客户看到底是那个字段的数据有问题,这个时候,失败了的数据,可能就会用到map,jsonobject等,目前发现写到excel中,
public class FileWriteStream {
public static final String errorReason = "导入失败原因";
public final File file;
private final ExcelWriter excelWriter;
private boolean isClosed = false;
private int recordCount = 0;
private final int maxRecords;
}
这是测试写入的代码,可以参考一下,
/**
* 错误文件写入
* @param errorData
*/
private void writeErrorToFile(Map<String,Object> errorData) {
try {
if (importContext.currentFileStream == null || importContext.currentFileStream.isFull()) {
if (importContext.currentFileStream != null) {
importContext.currentFileStream.close();
if (importContext.currentFileStream.file != null) {
importContext.tempErrorFiles.add(importContext.currentFileStream.file);
}
}
File newTempFile = File.createTempFile("error_", ".xlsx");
importContext.currentFileStream = new FileWriteStream(importContext.handler.getDTOClass(),newTempFile, importContext.maxRecordsPerFile);
}
importContext.currentFileStream.write(errorData);
} catch (Exception e) {
log.error("写入错误记录到临时文件失败", e);
}
}
Beta Was this translation helpful? Give feedback.
All reactions