fix:对比导出问题
This commit is contained in:
+86
-71
@@ -23,8 +23,8 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||
import org.apache.poi.hssf.usermodel.*;
|
||||
import org.apache.poi.hssf.util.HSSFColor;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -309,7 +309,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
//超链接样式
|
||||
CellStyle cellStyleLink =workbook.createCellStyle();
|
||||
HSSFFont font = ((HSSFWorkbook) workbook).createFont();
|
||||
font.setColor(HSSFColor.HSSFColorPredefined.LIGHT_BLUE.getIndex());
|
||||
// font.setColor(HSSFColor.HSSFColorPredefined.LIGHT_BLUE.getIndex());
|
||||
cellStyleLink.setFont(font);
|
||||
cellStyleLink.setWrapText(true);
|
||||
int i = 1;
|
||||
@@ -336,6 +336,9 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
log.info("-------------- 开始开始拆分左侧图片、文字、表格 :" + text + "-----------------");
|
||||
rowDataAndPathLeft = getSplitContent(request, text);
|
||||
log.info("-------------- 左侧图片、文字、表格 拆分成功 :"+ rowDataAndPathLeft +"-----------------");
|
||||
if (rowDataAndPathLeft.startsWith("---")){
|
||||
rowDataAndPathLeft = rowDataAndPathLeft.replaceFirst("---", "");
|
||||
}
|
||||
leftSplit = rowDataAndPathLeft.split("---");
|
||||
if (leftSplit.length > 1) {
|
||||
for (int j = 0; j < leftSplit.length; j++) {
|
||||
@@ -379,6 +382,9 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
log.info("-------------- 开始开始拆分右侧图片、文字、表格 :"+ text +" -----------------");
|
||||
rowDataAndPathRight = getSplitContent(request, text);
|
||||
log.info("-------------- 右侧图片、文字、表格 拆分成功 :"+ rowDataAndPathRight +" -----------------");
|
||||
if (rowDataAndPathRight.startsWith("---")){
|
||||
rowDataAndPathRight = rowDataAndPathRight.replaceFirst("---", "");
|
||||
}
|
||||
rightSplit = rowDataAndPathRight.split("---");
|
||||
if (rightSplit.length > 1) {
|
||||
for (int j = 0; j < rightSplit.length; j++) {
|
||||
@@ -409,76 +415,85 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
}
|
||||
}
|
||||
|
||||
// 左、右条款内容
|
||||
String leftContent = String.valueOf(row.getCell(3));
|
||||
String rightContent = String.valueOf(row.getCell(7));
|
||||
// 左、右条款名称
|
||||
String leftName = String.valueOf(row.getCell(2));
|
||||
String rightName = String.valueOf(row.getCell(6));
|
||||
// 左右条款内容对比
|
||||
if (StringUtils.isNotBlank(leftContent) && StringUtils.isNotBlank(rightContent)) {
|
||||
// 获取对比结果
|
||||
DiffUtils dmp = new DiffUtils();
|
||||
List<String> htmlDiffStrContent = dmp.getHtmlDiffStr(leftContent, rightContent);
|
||||
List<String> htmlDiffStrName = dmp.getHtmlDiffStr(leftName, rightName);
|
||||
Integer leftStart = sarFileCompareExcelMergeCell.getLeftStart();
|
||||
Integer leftEnd = sarFileCompareExcelMergeCell.getLeftEnd();
|
||||
if (!Objects.isNull(leftStart) || !Objects.isNull(leftEnd)) {
|
||||
int rows = Math.max(leftEnd - leftStart, 1);
|
||||
for (int j = 0; j <= rows; j++) {
|
||||
Row row1 = sheet.getRow(j + leftStart);
|
||||
// 左、右条款内容
|
||||
String leftContent = String.valueOf(Objects.isNull(row1.getCell(3)) ? "" : row1.getCell(3));
|
||||
String rightContent = String.valueOf(Objects.isNull(row1.getCell(7)) ? "" : row1.getCell(7));
|
||||
// 左、右条款名称
|
||||
String leftName = String.valueOf(row1.getCell(2));
|
||||
String rightName = String.valueOf(row1.getCell(6));
|
||||
// 左右条款内容对比
|
||||
if ((StringUtils.isNotBlank(leftContent) || StringUtils.isNotBlank(rightContent))) {
|
||||
// 获取对比结果
|
||||
DiffUtils dmp = new DiffUtils();
|
||||
List<String> htmlDiffStrContent = dmp.getHtmlDiffStr(leftContent, rightContent);
|
||||
List<String> htmlDiffStrName = dmp.getHtmlDiffStr(leftName, rightName);
|
||||
|
||||
Font redFont = workbook.createFont();
|
||||
redFont.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
|
||||
Font greenFont = workbook.createFont();
|
||||
greenFont.setColor(HSSFColor.HSSFColorPredefined.GREEN.getIndex());
|
||||
Font redFont = workbook.createFont();
|
||||
redFont.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
|
||||
Font greenFont = workbook.createFont();
|
||||
greenFont.setColor(HSSFColor.HSSFColorPredefined.GREEN.getIndex());
|
||||
|
||||
// 获取红色字体标签的所有下标位置
|
||||
String redTag = "<span class=\"delClass\">";
|
||||
List<String> leftContentRedTagIndex = getTagIndex(htmlDiffStrContent.get(0), redTag);
|
||||
HSSFRichTextString leftRich = new HSSFRichTextString(
|
||||
htmlDiffStrContent.get(0)
|
||||
.replace(redTag, "")
|
||||
.replace("</span>", ""));
|
||||
for (String tagIndex : leftContentRedTagIndex) {
|
||||
// 设置单独字体样式
|
||||
String[] split = tagIndex.split(",");
|
||||
leftRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), redFont);
|
||||
row.createCell(3).setCellValue(leftRich);
|
||||
// 获取红色字体标签的所有下标位置
|
||||
String redTag = "<span class=\"delClass\">";
|
||||
List<String> leftContentRedTagIndex = getTagIndex(htmlDiffStrContent.get(0), redTag);
|
||||
HSSFRichTextString leftRich = new HSSFRichTextString(
|
||||
htmlDiffStrContent.get(0)
|
||||
.replace(redTag, "")
|
||||
.replace("</span>", ""));
|
||||
for (String tagIndex : leftContentRedTagIndex) {
|
||||
// 设置单独字体样式
|
||||
String[] split = tagIndex.split(",");
|
||||
leftRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), redFont);
|
||||
row1.createCell(3).setCellValue(leftRich);
|
||||
}
|
||||
|
||||
// 获取绿色字体标签的所有下标位置
|
||||
String greenTag = "<span class=\"insertClass\">";
|
||||
List<String> rightContentGreenTagIndex = getTagIndex(htmlDiffStrContent.get(1), greenTag);
|
||||
HSSFRichTextString rightRich = new HSSFRichTextString(
|
||||
htmlDiffStrContent.get(1)
|
||||
.replace(greenTag, "")
|
||||
.replace("</span>", ""));
|
||||
for (String tagIndex : rightContentGreenTagIndex) {
|
||||
// 设置单独字体样式
|
||||
String[] split = tagIndex.split(",");
|
||||
rightRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), greenFont);
|
||||
row1.createCell(7).setCellValue(rightRich);
|
||||
}
|
||||
|
||||
// 设置标题单独字体样式
|
||||
List<String> leftNameRedTagIndex = getTagIndex(htmlDiffStrName.get(0), redTag);
|
||||
HSSFRichTextString leftNameRich = new HSSFRichTextString(
|
||||
htmlDiffStrName.get(0)
|
||||
.replace(redTag, "")
|
||||
.replace("</span>", ""));
|
||||
for (String tagIndex : leftNameRedTagIndex) {
|
||||
// 设置单独字体样式
|
||||
String[] split = tagIndex.split(",");
|
||||
leftNameRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), redFont);
|
||||
row1.createCell(2).setCellValue(leftNameRich);
|
||||
}
|
||||
|
||||
List<String> rightNameGreenTagIndex = getTagIndex(htmlDiffStrName.get(1), greenTag);
|
||||
HSSFRichTextString rightNameRich = new HSSFRichTextString(
|
||||
htmlDiffStrName.get(1)
|
||||
.replace(greenTag, "")
|
||||
.replace("</span>", ""));
|
||||
for (String tagIndex : rightNameGreenTagIndex) {
|
||||
// 设置单独字体样式
|
||||
String[] split = tagIndex.split(",");
|
||||
rightNameRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), greenFont);
|
||||
row1.createCell(6).setCellValue(rightNameRich);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取绿色字体标签的所有下标位置
|
||||
String greenTag = "<span class=\"insertClass\">";
|
||||
List<String> rightContentGreenTagIndex = getTagIndex(htmlDiffStrContent.get(1), greenTag);
|
||||
HSSFRichTextString rightRich = new HSSFRichTextString(
|
||||
htmlDiffStrContent.get(1)
|
||||
.replace(greenTag, "")
|
||||
.replace("</span>", ""));
|
||||
for (String tagIndex : rightContentGreenTagIndex) {
|
||||
// 设置单独字体样式
|
||||
String[] split = tagIndex.split(",");
|
||||
rightRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), greenFont);
|
||||
row.createCell(7).setCellValue(rightRich);
|
||||
}
|
||||
|
||||
// 设置标题单独字体样式
|
||||
List<String> leftNameRedTagIndex = getTagIndex(htmlDiffStrName.get(0), redTag);
|
||||
HSSFRichTextString leftNameRich = new HSSFRichTextString(
|
||||
htmlDiffStrName.get(0)
|
||||
.replace(redTag, "")
|
||||
.replace("</span>", ""));
|
||||
for (String tagIndex : leftNameRedTagIndex) {
|
||||
// 设置单独字体样式
|
||||
String[] split = tagIndex.split(",");
|
||||
leftNameRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), redFont);
|
||||
row.createCell(2).setCellValue(leftNameRich);
|
||||
}
|
||||
|
||||
List<String> rightNameGreenTagIndex = getTagIndex(htmlDiffStrName.get(1), greenTag);
|
||||
HSSFRichTextString rightNameRich = new HSSFRichTextString(
|
||||
htmlDiffStrName.get(1)
|
||||
.replace(greenTag, "")
|
||||
.replace("</span>", ""));
|
||||
for (String tagIndex : rightNameGreenTagIndex) {
|
||||
// 设置单独字体样式
|
||||
String[] split = tagIndex.split(",");
|
||||
rightNameRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), greenFont);
|
||||
row.createCell(6).setCellValue(rightNameRich);
|
||||
}
|
||||
}
|
||||
|
||||
row.createCell(8).setCellValue(itemComment.getComment());
|
||||
@@ -643,6 +658,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
tableAssociate(workbook, cellStyleLink, cell, text);
|
||||
log.info("-------------------------表格处理完毕----------------------------");
|
||||
} else {
|
||||
text = text.replace("<p style=\"text-align: center;\">", "");
|
||||
cell.setCellValue(text);
|
||||
}
|
||||
}
|
||||
@@ -719,7 +735,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
textAndImg = left + "---" + table + "---" + right;
|
||||
splitTable(textAndImg, session);
|
||||
} else {
|
||||
session.setAttribute("textAndTableAndImg", textAndImg);
|
||||
session.setAttribute("textAndTableAndImg", textAndImg.replace("------", "---"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -738,7 +754,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
text = txtLeft + "---" + path + "---" + txtRight;
|
||||
splitImg(text, session);
|
||||
} else {
|
||||
session.setAttribute("txtAndImg", text);
|
||||
session.setAttribute("txtAndImg", text.replace("------", "---"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -781,5 +797,4 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
bos.close(); // 后开先关
|
||||
bis.close(); // 先开后关
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user