拆分导出-解决条款内容超出excel单元格字符最大长度问题
This commit is contained in:
+63
-2
@@ -3145,7 +3145,8 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
BASE64Decoder base64Decoder = new BASE64Decoder();
|
||||
if (getValList != null && !getValList.isEmpty()) {
|
||||
String preType = "";
|
||||
for(SarFileSplitItemsValEO itemsValEO : getValList){
|
||||
for (int i = 0; i < getValList.size(); i++) {
|
||||
SarFileSplitItemsValEO itemsValEO = getValList.get(i);
|
||||
String type = itemsValEO.getType();
|
||||
FileSplitValExportDto lastOne = new FileSplitValExportDto();
|
||||
lastOne.setValType(type);
|
||||
@@ -3153,10 +3154,23 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
lastOne = valContent.get(valContent.size() - 1);
|
||||
lastOne.setValContent(lastOne.getValContent()+itemsValEO.getItemContent() + "\n");
|
||||
valContent.set(valContent.size() - 1, lastOne);
|
||||
|
||||
//循环到最后一次是文本的情况
|
||||
if(getValList.size() == (i+1)){
|
||||
splitContext(valContent);
|
||||
}
|
||||
|
||||
} else if ("TEXT".equals(type)) {
|
||||
lastOne.setValContent(lastOne.getValContent()+itemsValEO.getItemContent() + "\n");
|
||||
valContent.add(lastOne);
|
||||
|
||||
//第一次
|
||||
splitContext(valContent);
|
||||
|
||||
} else if ("TABLE".equals(type)) {
|
||||
//上次是TEXT类型的时候
|
||||
splitContext(valContent);
|
||||
|
||||
String tableName = String.valueOf(tableIndex);
|
||||
lastOne.setValContent("tableSheet" + tableName);
|
||||
//查询table信息
|
||||
@@ -3172,6 +3186,9 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
tableIndex++;
|
||||
page.setTableIndex(tableIndex);
|
||||
} else if ("IMG".equals(type)) {
|
||||
//上次是TEXT类型的时候
|
||||
splitContext(valContent);
|
||||
|
||||
String imgContent = itemsValEO.getItemContent();
|
||||
String imgUUIndex = "img" + String.valueOf(imgIndex);
|
||||
if (com.jero.modules.system.util.StringUtils.isNotEmpty(imgContent)){
|
||||
@@ -3222,6 +3239,50 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
return valContent;
|
||||
}
|
||||
|
||||
private void splitContext(List<FileSplitValExportDto> valContent){
|
||||
FileSplitValExportDto fileSplitValExportDto = valContent.get(valContent.size() - 1); // 始终判断最后一个内容是否超出长度
|
||||
int lastIndex = valContent.size() - 1;
|
||||
if ("TEXT".equals(fileSplitValExportDto.getValType())) {
|
||||
String dtoValContent = fileSplitValExportDto.getValContent();
|
||||
//判断是否超长
|
||||
if(dtoValContent.length() > 30000){ // 若超出长度
|
||||
// 先移除再添加
|
||||
valContent.remove(lastIndex);
|
||||
|
||||
//拆分数据
|
||||
List<String> content = new ArrayList<>(); // 存放拆出来的内容
|
||||
int lastLength = 0;
|
||||
while (lastLength < dtoValContent.length()) {
|
||||
if (lastLength == 0) {
|
||||
String contentOld = dtoValContent.substring(0, 30000);
|
||||
String contentNew = contentOld.substring(0,contentOld.lastIndexOf("\n")+1);
|
||||
content.add(contentNew);
|
||||
lastLength = 30000;
|
||||
} else if (lastLength > dtoValContent.length() - 30000) {
|
||||
String contentOld = dtoValContent.substring(lastLength, dtoValContent.length());
|
||||
String contentNew = contentOld.substring(0,contentOld.lastIndexOf("\n")+1);
|
||||
content.add(contentNew);
|
||||
lastLength = dtoValContent.length();
|
||||
} else{
|
||||
String contentOld = dtoValContent.substring(lastLength, lastLength + 30000);
|
||||
String contentNew = contentOld.substring(0,contentOld.lastIndexOf("\n")+1);
|
||||
content.add(contentNew);
|
||||
lastLength = lastLength + 30000;
|
||||
}
|
||||
}
|
||||
|
||||
// 添加
|
||||
for (String c : content) {
|
||||
FileSplitValExportDto dto = new FileSplitValExportDto();
|
||||
dto.setValType(fileSplitValExportDto.getValType());
|
||||
dto.setValContent(c);
|
||||
valContent.add(dto);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void downLoadImgList(List<FileSplitValImgExportDto> allImgList, String fileNowPath) throws IOException {
|
||||
for(FileSplitValImgExportDto imgExportDto : allImgList){
|
||||
@@ -3428,7 +3489,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
cell2.setHyperlink(hyperlink1);// 链接
|
||||
row1.getCell(cellNum).setCellStyle(cellStyleLink);
|
||||
}
|
||||
cell2.setCellValue(content);
|
||||
cell2.setCellValue(content); // IllegalArgumentException异常,excel单元格最大字符长度有限制
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user