方法名称优化

This commit is contained in:
CD
2022-10-10 10:21:57 +08:00
parent 1ec0784eb6
commit 62a87236aa
@@ -288,9 +288,9 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
if (ObjectUtils.isEmpty(row2)) {
row2 = sheet.createRow(j + i);
}
imgToExcel(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row2, i, j, leftSplit[j], 3);
handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row2, i, j, leftSplit[j], 3);
} else {
imgToExcel(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row, i, j, leftSplit[j], 3);
handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row, i, j, leftSplit[j], 3);
}
}
}
@@ -322,9 +322,9 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
if (ObjectUtils.isEmpty(row2)) {
row2 = sheet.createRow(j + i);
}
imgToExcel(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row2, i, j, rightSplit[j], 7);
handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row2, i, j, rightSplit[j], 7);
} else {
imgToExcel(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row, i, j, rightSplit[j], 7);
handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row, i, j, rightSplit[j], 7);
}
}
}
@@ -401,7 +401,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
}
/**
* 将图片添加到excel指定单元格中
* 处理图片跟表格类型的数据
* @param workbook
* @param dir
* @param patriarch
@@ -414,7 +414,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
* @param cellNum
* @throws IOException
*/
private void imgToExcel(Workbook workbook, String dir, HSSFPatriarch patriarch, CellStyle cellStyleLink, ByteArrayOutputStream byteArrayOut, Row row, int i, int j, String text, int cellNum) throws IOException {
private void handleSpecificData(Workbook workbook, String dir, HSSFPatriarch patriarch, CellStyle cellStyleLink, ByteArrayOutputStream byteArrayOut, Row row, int i, int j, String text, int cellNum) throws IOException {
if (text.contains("/upFiles")) {
row.setHeight((short) 3000); //设置行高
//先将图片下载到本地
@@ -439,7 +439,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
} else {
Cell cell = row.createCell(cellNum);
if (text.contains("<table")) {
tableAssociations(workbook, cellStyleLink, cell, text);
tableAssociate(workbook, cellStyleLink, cell, text);
} else {
cell.setCellValue(text);
}
@@ -453,7 +453,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
* @param cell
* @param tableHtml
*/
private void tableAssociations(Workbook workbook, CellStyle cellStyleLink, Cell cell, String tableHtml) {
private void tableAssociate(Workbook workbook, CellStyle cellStyleLink, Cell cell, String tableHtml) {
cell.setCellValue("点击查看详情");
//新开sheet生成表格
if (org.apache.commons.lang.StringUtils.isNotEmpty(tableHtml) && tableHtml.indexOf("<tbody>") < 0) {
@@ -487,7 +487,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
private String getSplitContent(HttpServletRequest request, String text) {
text = text.replace("<p>", "").replace("</p>", "\r\n");
//分割图片
addImgdata(text, request.getSession());
splitImg(text, request.getSession());
//分割表格
String txtAndImg = (String) request.getSession().getAttribute("txtAndImg");
txtAndImg = txtAndImg.replaceAll("table", "replaceTable");
@@ -514,18 +514,19 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
}
/**
* 提取字符串中<img>标签内容中的图片路径,并重新按顺序拼接
* 分割图片
* @param text
* @param session
* @return
*/
private void addImgdata(String text,HttpSession session) {
private void splitImg(String text,HttpSession session) {
if (text.contains("<img")) {
String txtLeft = text.substring(0, text.indexOf("<img"));
String txtRight = text.substring(text.indexOf("g\">") + 3);
String img = text.substring(text.indexOf("<img"), text.indexOf("g\">"));
String path = img.substring(img.lastIndexOf("=") + 1)+"g";
text = txtLeft + "---" + path + "---" + txtRight;
addImgdata(text, session);
splitImg(text, session);
} else {
session.setAttribute("txtAndImg", text);
}