拆分对比-导出全文对比。
This commit is contained in:
+194
-88
@@ -534,6 +534,19 @@ public class SarFileCompareInfoServiceImpl extends ServiceImpl<SarFileCompareInf
|
|||||||
if (StringUtils.isNotEmpty(exportName)) {
|
if (StringUtils.isNotEmpty(exportName)) {
|
||||||
fileOriName = exportName;
|
fileOriName = exportName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CellStyle cellStyle = workbook.createCellStyle();//初始化单元格格式对象
|
||||||
|
cellStyle.setAlignment(HorizontalAlignment.LEFT);
|
||||||
|
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
cellStyle.setWrapText(true);
|
||||||
|
|
||||||
|
//超链接样式
|
||||||
|
CellStyle cellStyleLink =workbook.createCellStyle();
|
||||||
|
HSSFFont font = ((HSSFWorkbook) workbook).createFont();
|
||||||
|
font.setColor(HSSFColor.HSSFColorPredefined.LIGHT_BLUE.getIndex());
|
||||||
|
cellStyleLink.setFont(font);
|
||||||
|
cellStyleLink.setWrapText(true);
|
||||||
|
|
||||||
String[] headers = {"条款号","条款名称","条款内容","备注"};
|
String[] headers = {"条款号","条款名称","条款内容","备注"};
|
||||||
HSSFSheet sheetItemsLeft = workbook.createSheet("旧文档");
|
HSSFSheet sheetItemsLeft = workbook.createSheet("旧文档");
|
||||||
// 左侧在excel表中添加表头
|
// 左侧在excel表中添加表头
|
||||||
@@ -580,116 +593,209 @@ public class SarFileCompareInfoServiceImpl extends ServiceImpl<SarFileCompareInf
|
|||||||
List<SarFileCompareItem> leftData = itemMap.get(CompareConst.POS_LEFT);
|
List<SarFileCompareItem> leftData = itemMap.get(CompareConst.POS_LEFT);
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(leftData)) {
|
if (CollectionUtils.isNotEmpty(leftData)) {
|
||||||
//记录需要合并的单元格
|
|
||||||
List<SarFileCompareExcelMergeCell> mergeCells = new ArrayList<>();
|
|
||||||
|
|
||||||
for (int rowNum = 0; rowNum < leftData.size(); rowNum++) {
|
int i = 1;
|
||||||
SarFileCompareExcelMergeCell sarFileCompareExcelMergeCell = new SarFileCompareExcelMergeCell();
|
for (SarFileCompareItem sarFileCompareItem : leftData) {
|
||||||
|
HSSFRow row1 = sheetItemsLeft.createRow(i);
|
||||||
SarFileCompareItem sarFileCompareItem = leftData.get(rowNum);
|
|
||||||
|
|
||||||
HSSFRow row1 = sheetItemsLeft.createRow(rowNum + 1);
|
|
||||||
row1.createCell(0).setCellValue(sfcInfo.getSerialNumberLeft() + " " +sfcInfo.getTitleLeft());
|
row1.createCell(0).setCellValue(sfcInfo.getSerialNumberLeft() + " " +sfcInfo.getTitleLeft());
|
||||||
row1.createCell(1).setCellValue(sarFileCompareItem.getItemsNum());
|
row1.createCell(1).setCellValue(sarFileCompareItem.getItemsNum());
|
||||||
row1.getCell(1).setCellStyle(cellStyleBase);
|
row1.getCell(1).setCellStyle(cellStyleBase);
|
||||||
|
|
||||||
String itemText = sarFileCompareItem.getItemsText();
|
String itemContent = sarFileCompareItem.getItemsText();
|
||||||
List<MarkTextVO> addList = new ArrayList<>();
|
|
||||||
List<MarkTextVO> delList = new ArrayList<>();
|
|
||||||
itemText = HtmlTextExcel.changeHtmlToExcel(sheetItemsLeft,workbook,request,itemText,addList,delList);
|
|
||||||
HSSFRichTextString ts= new HSSFRichTextString(itemText);
|
|
||||||
if (addList != null && !addList.isEmpty()) {
|
|
||||||
for (MarkTextVO markTextVO : addList) {
|
|
||||||
int stIndex = markTextVO.getStartIndex();
|
|
||||||
int edIndex = markTextVO.getEndIndex();
|
|
||||||
ts.applyFont(stIndex,edIndex,fontAdd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (delList != null && !delList.isEmpty()) {
|
|
||||||
for (MarkTextVO markTextVO : delList) {
|
|
||||||
int stIndex = markTextVO.getStartIndex();
|
|
||||||
int edIndex = markTextVO.getEndIndex();
|
|
||||||
ts.applyFont(stIndex,edIndex,fontDel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
row1.createCell(2).setCellValue(sarFileCompareItem.getItemsName());
|
|
||||||
row1.createCell(3).setCellValue(ts);
|
|
||||||
row1.getCell(3).setCellStyle(cellStyleBase);
|
|
||||||
row1.createCell(4).setCellValue(sarFileCompareItem.getRemark());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ObjectUtils.isNotEmpty(mergeCells)) {
|
List<SarFileCompareExcelMergeCell> mergeCells = new ArrayList<>();
|
||||||
log.info("-------------- 开始处理需要合并的单元格 -----------------");
|
String[] leftSplit = null;
|
||||||
Set<SarFileCompareExcelMergeCell> mergeCellSet = new HashSet<>(mergeCells);
|
if (StringUtils.isNotEmpty(itemContent)) {
|
||||||
for (SarFileCompareExcelMergeCell mergeCell : mergeCellSet) {
|
String rowDataAndPath = HtmlTextExcel.getSplitContent(request, itemContent);
|
||||||
Integer leftCount = 0;
|
HSSFPatriarch patriarch = (HSSFPatriarch) sheetItemsLeft.createDrawingPatriarch();
|
||||||
if (ObjectUtils.isNotEmpty(mergeCell.getLeftEnd())&&ObjectUtils.isNotEmpty(mergeCell.getLeftStart())) {
|
|
||||||
leftCount = mergeCell.getLeftEnd() - mergeCell.getLeftStart() + 1;
|
leftSplit = rowDataAndPath.split("---");
|
||||||
}
|
|
||||||
Integer rightCount = 0;
|
if (leftSplit.length > 1) {
|
||||||
if (ObjectUtils.isNotEmpty(mergeCell.getRightEnd())&&ObjectUtils.isNotEmpty(mergeCell.getRightStart())) {
|
for (int j = 0; j < leftSplit.length; j++) {
|
||||||
rightCount = mergeCell.getRightEnd() - mergeCell.getRightStart() + 1;
|
if (ObjectUtils.isNotEmpty(leftSplit[j])) {
|
||||||
}
|
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
|
||||||
Integer start = leftCount - rightCount >= 0 ? mergeCell.getLeftStart() : mergeCell.getRightStart();
|
if (j > 0) {
|
||||||
log.info("-------------- 合并开始行数:" + start + " -----------------");
|
Row row2 = sheetItemsLeft.getRow(j + i);
|
||||||
Integer end = leftCount - rightCount >= 0 ? mergeCell.getLeftEnd() : mergeCell.getRightEnd();
|
if (ObjectUtils.isEmpty(row2)) {
|
||||||
log.info("-------------- 合并结束行数: " + end + " -----------------");
|
row2 = sheetItemsLeft.createRow(j + i);
|
||||||
//合并
|
}
|
||||||
if (ObjectUtils.isNotEmpty(start)&&ObjectUtils.isNotEmpty(end)) {
|
log.info("-------------- 开始开始处理左侧图片、表格 -----------------");
|
||||||
CellRangeAddress region0 = new CellRangeAddress(start, end, 0, 0);
|
try {
|
||||||
sheetItemsLeft.addMergedRegion(region0);
|
HtmlTextExcel.handleSpecificData(workbook, patriarch, cellStyleLink, byteArrayOut, row2, i, j, leftSplit[j], 2);
|
||||||
CellRangeAddress region1 = new CellRangeAddress(start, end, 1, 1);
|
} catch (IOException e) {
|
||||||
sheetItemsLeft.addMergedRegion(region1);
|
e.printStackTrace();
|
||||||
CellRangeAddress region2 = new CellRangeAddress(start, end, 2, 2);
|
}
|
||||||
sheetItemsLeft.addMergedRegion(region2);
|
log.info("-------------- 左侧图片、表格 处理成功 -----------------");
|
||||||
CellRangeAddress region4 = new CellRangeAddress(start, end, 4, 4);
|
} else {
|
||||||
sheetItemsLeft.addMergedRegion(region4);
|
log.info("-------------- 开始开始处理左侧图片、表格 -----------------");
|
||||||
CellRangeAddress region5 = new CellRangeAddress(start, end, 5, 5);
|
try {
|
||||||
sheetItemsLeft.addMergedRegion(region5);
|
HtmlTextExcel.handleSpecificData(workbook, patriarch, cellStyleLink, byteArrayOut, row1, i, j, leftSplit[j], 2);
|
||||||
CellRangeAddress region6 = new CellRangeAddress(start, end, 6, 6);
|
} catch (IOException e) {
|
||||||
sheetItemsLeft.addMergedRegion(region6);
|
e.printStackTrace();
|
||||||
CellRangeAddress region7 = new CellRangeAddress(start, end, 8, 8);
|
}
|
||||||
sheetItemsLeft.addMergedRegion(region7);
|
log.info("-------------- 左侧图片、表格 处理成功 -----------------");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SarFileCompareExcelMergeCell sarFileCompareExcelMergeCell = new SarFileCompareExcelMergeCell();
|
||||||
|
sarFileCompareExcelMergeCell.setLeftStart(i);
|
||||||
|
sarFileCompareExcelMergeCell.setLeftEnd(i + leftSplit.length - 1);
|
||||||
|
sarFileCompareExcelMergeCell.setRightStart(0);
|
||||||
|
sarFileCompareExcelMergeCell.setRightEnd(0);
|
||||||
|
mergeCells.add(sarFileCompareExcelMergeCell);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
String text = HtmlTextExcel.changeHtmlToExcel(itemContent, null, null);
|
||||||
|
row1.createCell(2).setCellValue(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ObjectUtils.isNotEmpty(mergeCells)) {
|
||||||
|
log.info("-------------- 开始处理需要合并的单元格 -----------------");
|
||||||
|
Set<SarFileCompareExcelMergeCell> mergeCellSet = new HashSet<>(mergeCells);
|
||||||
|
for (SarFileCompareExcelMergeCell mergeCell : mergeCellSet) {
|
||||||
|
Integer leftCount = 0;
|
||||||
|
if (ObjectUtils.isNotEmpty(mergeCell.getLeftEnd())&&ObjectUtils.isNotEmpty(mergeCell.getLeftStart())) {
|
||||||
|
leftCount = mergeCell.getLeftEnd() - mergeCell.getLeftStart() + 1;
|
||||||
|
}
|
||||||
|
Integer rightCount = 0;
|
||||||
|
if (ObjectUtils.isNotEmpty(mergeCell.getRightEnd())&&ObjectUtils.isNotEmpty(mergeCell.getRightStart())) {
|
||||||
|
rightCount = mergeCell.getRightEnd() - mergeCell.getRightStart() + 1;
|
||||||
|
}
|
||||||
|
Integer start = leftCount - rightCount >= 0 ? mergeCell.getLeftStart() : mergeCell.getRightStart();
|
||||||
|
log.info("-------------- 合并开始行数:" + start + " -----------------");
|
||||||
|
Integer end = leftCount - rightCount >= 0 ? mergeCell.getLeftEnd() : mergeCell.getRightEnd();
|
||||||
|
log.info("-------------- 合并结束行数: " + end + " -----------------");
|
||||||
|
//合并
|
||||||
|
if (ObjectUtils.isNotEmpty(start)&&ObjectUtils.isNotEmpty(end)) {
|
||||||
|
CellRangeAddress region0 = new CellRangeAddress(start, end, 0, 0);
|
||||||
|
sheetItemsLeft.addMergedRegion(region0);
|
||||||
|
CellRangeAddress region1 = new CellRangeAddress(start, end, 1, 1);
|
||||||
|
sheetItemsLeft.addMergedRegion(region1);
|
||||||
|
CellRangeAddress region3 = new CellRangeAddress(start, end, 3, 3);
|
||||||
|
sheetItemsLeft.addMergedRegion(region3);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
log.info("-------------- 单元格合并成功 -----------------");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.info("-------------- 单元格合并成功 -----------------");
|
|
||||||
|
row1.createCell(3).setCellValue(sarFileCompareItem.getRemark());
|
||||||
|
|
||||||
|
row1.setRowStyle(cellStyle);
|
||||||
|
for (int j = 0; j <= 3; j++) {
|
||||||
|
Cell cell = row1.getCell(j);
|
||||||
|
if (null != cell) {
|
||||||
|
cell.setCellStyle(cellStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int left_length = ObjectUtils.isEmpty(leftSplit) ? 1 : leftSplit.length;
|
||||||
|
i = i + left_length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SarFileCompareItem> rightData = itemMap.get(CompareConst.POS_RIGHT);
|
List<SarFileCompareItem> rightData = itemMap.get(CompareConst.POS_RIGHT);
|
||||||
if (CollectionUtils.isNotEmpty(rightData)) {
|
if (CollectionUtils.isNotEmpty(rightData)) {
|
||||||
for (int rowNum = 0; rowNum < rightData.size(); rowNum++) {
|
int i = 1;
|
||||||
SarFileCompareItem sarFileCompareItem = rightData.get(rowNum);
|
for (SarFileCompareItem sarFileCompareItem : rightData) {
|
||||||
|
HSSFRow row1 = sheetItemsRight.createRow(i);
|
||||||
HSSFRow row1 = sheetItemsRight.createRow(rowNum + 1);
|
|
||||||
row1.createCell(0).setCellValue(sfcInfo.getSerialNumberRight() + " " +sfcInfo.getTitleRight());
|
row1.createCell(0).setCellValue(sfcInfo.getSerialNumberRight() + " " +sfcInfo.getTitleRight());
|
||||||
row1.createCell(1).setCellValue(sarFileCompareItem.getItemsNum());
|
row1.createCell(1).setCellValue(sarFileCompareItem.getItemsNum());
|
||||||
row1.getCell(1).setCellStyle(cellStyleBase);
|
row1.getCell(1).setCellStyle(cellStyleBase);
|
||||||
|
|
||||||
String itemText = sarFileCompareItem.getItemsText();
|
String itemContent = sarFileCompareItem.getItemsText();
|
||||||
List<MarkTextVO> addList = new ArrayList<>();
|
List<SarFileCompareExcelMergeCell> mergeCells = new ArrayList<>();
|
||||||
List<MarkTextVO> delList = new ArrayList<>();
|
String[] rightSplit = null;
|
||||||
itemText = HtmlTextExcel.changeHtmlToExcel(sheetItemsRight,workbook,request,itemText,addList,delList);
|
if (StringUtils.isNotEmpty(itemContent)) {
|
||||||
HSSFRichTextString ts= new HSSFRichTextString(itemText);
|
String rowDataAndPath = HtmlTextExcel.getSplitContent(request, itemContent);
|
||||||
if (addList != null && !addList.isEmpty()) {
|
HSSFPatriarch patriarch = (HSSFPatriarch) sheetItemsRight.createDrawingPatriarch();
|
||||||
for (MarkTextVO markTextVO : addList) {
|
|
||||||
int stIndex = markTextVO.getStartIndex();
|
rightSplit = rowDataAndPath.split("---");
|
||||||
int edIndex = markTextVO.getEndIndex();
|
|
||||||
ts.applyFont(stIndex,edIndex,fontAdd);
|
if (rightSplit.length > 1) {
|
||||||
|
for (int j = 0; j < rightSplit.length; j++) {
|
||||||
|
if (ObjectUtils.isNotEmpty(rightSplit[j])) {
|
||||||
|
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
|
||||||
|
if (j > 0) {
|
||||||
|
Row row2 = sheetItemsRight.getRow(j + i);
|
||||||
|
if (ObjectUtils.isEmpty(row2)) {
|
||||||
|
row2 = sheetItemsRight.createRow(j + i);
|
||||||
|
}
|
||||||
|
log.info("-------------- 开始开始处理左侧图片、表格 -----------------");
|
||||||
|
try {
|
||||||
|
HtmlTextExcel.handleSpecificData(workbook, patriarch, cellStyleLink, byteArrayOut, row2, i, j, rightSplit[j], 2);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
log.info("-------------- 左侧图片、表格 处理成功 -----------------");
|
||||||
|
} else {
|
||||||
|
log.info("-------------- 开始开始处理左侧图片、表格 -----------------");
|
||||||
|
try {
|
||||||
|
HtmlTextExcel.handleSpecificData(workbook, patriarch, cellStyleLink, byteArrayOut, row1, i, j, rightSplit[j], 2);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
log.info("-------------- 左侧图片、表格 处理成功 -----------------");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SarFileCompareExcelMergeCell sarFileCompareExcelMergeCell = new SarFileCompareExcelMergeCell();
|
||||||
|
sarFileCompareExcelMergeCell.setLeftStart(i);
|
||||||
|
sarFileCompareExcelMergeCell.setLeftEnd(i + rightSplit.length - 1);
|
||||||
|
sarFileCompareExcelMergeCell.setRightStart(0);
|
||||||
|
sarFileCompareExcelMergeCell.setRightEnd(0);
|
||||||
|
mergeCells.add(sarFileCompareExcelMergeCell);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
String text = HtmlTextExcel.changeHtmlToExcel(itemContent, null, null);
|
||||||
|
row1.createCell(2).setCellValue(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ObjectUtils.isNotEmpty(mergeCells)) {
|
||||||
|
log.info("-------------- 开始处理需要合并的单元格 -----------------");
|
||||||
|
Set<SarFileCompareExcelMergeCell> mergeCellSet = new HashSet<>(mergeCells);
|
||||||
|
for (SarFileCompareExcelMergeCell mergeCell : mergeCellSet) {
|
||||||
|
Integer leftCount = 0;
|
||||||
|
if (ObjectUtils.isNotEmpty(mergeCell.getLeftEnd())&&ObjectUtils.isNotEmpty(mergeCell.getLeftStart())) {
|
||||||
|
leftCount = mergeCell.getLeftEnd() - mergeCell.getLeftStart() + 1;
|
||||||
|
}
|
||||||
|
Integer rightCount = 0;
|
||||||
|
if (ObjectUtils.isNotEmpty(mergeCell.getRightEnd())&&ObjectUtils.isNotEmpty(mergeCell.getRightStart())) {
|
||||||
|
rightCount = mergeCell.getRightEnd() - mergeCell.getRightStart() + 1;
|
||||||
|
}
|
||||||
|
Integer start = leftCount - rightCount >= 0 ? mergeCell.getLeftStart() : mergeCell.getRightStart();
|
||||||
|
log.info("-------------- 合并开始行数:" + start + " -----------------");
|
||||||
|
Integer end = leftCount - rightCount >= 0 ? mergeCell.getLeftEnd() : mergeCell.getRightEnd();
|
||||||
|
log.info("-------------- 合并结束行数: " + end + " -----------------");
|
||||||
|
//合并
|
||||||
|
if (ObjectUtils.isNotEmpty(start)&&ObjectUtils.isNotEmpty(end)) {
|
||||||
|
CellRangeAddress region0 = new CellRangeAddress(start, end, 0, 0);
|
||||||
|
sheetItemsRight.addMergedRegion(region0);
|
||||||
|
CellRangeAddress region1 = new CellRangeAddress(start, end, 1, 1);
|
||||||
|
sheetItemsRight.addMergedRegion(region1);
|
||||||
|
CellRangeAddress region3 = new CellRangeAddress(start, end, 3, 3);
|
||||||
|
sheetItemsRight.addMergedRegion(region3);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
log.info("-------------- 单元格合并成功 -----------------");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (delList != null && !delList.isEmpty()) {
|
|
||||||
for (MarkTextVO markTextVO : delList) {
|
row1.createCell(3).setCellValue(sarFileCompareItem.getRemark());
|
||||||
int stIndex = markTextVO.getStartIndex();
|
|
||||||
int edIndex = markTextVO.getEndIndex();
|
row1.setRowStyle(cellStyle);
|
||||||
ts.applyFont(stIndex,edIndex,fontDel);
|
for (int j = 0; j <= 3; j++) {
|
||||||
|
Cell cell = row1.getCell(j);
|
||||||
|
if (null != cell) {
|
||||||
|
cell.setCellStyle(cellStyle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
row1.createCell(2).setCellValue(sarFileCompareItem.getItemsName());
|
int left_length = ObjectUtils.isEmpty(rightSplit) ? 1 : rightSplit.length;
|
||||||
row1.createCell(3).setCellValue(ts);
|
i = i + left_length;
|
||||||
row1.getCell(3).setCellStyle(cellStyleBase);
|
|
||||||
row1.createCell(4).setCellValue(sarFileCompareItem.getRemark());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
@@ -92,6 +92,7 @@ public class SarItemsCompareHisEOServiceImpl extends ServiceImpl<SarItemsCompare
|
|||||||
String fileName = fileOriName + ".xlsx";
|
String fileName = fileOriName + ".xlsx";
|
||||||
ExportParams exportParams = new ExportParams();
|
ExportParams exportParams = new ExportParams();
|
||||||
exportParams.setType(ExcelType.XSSF);
|
exportParams.setType(ExcelType.XSSF);
|
||||||
|
exportParams.setSheetName("条款对比信息");
|
||||||
workbook = ExcelExportUtil.exportExcel(exportParams, SarItemsCompareHisEO.class, exportDataList);
|
workbook = ExcelExportUtil.exportExcel(exportParams, SarItemsCompareHisEO.class, exportDataList);
|
||||||
response.setHeader("Content-Disposition",
|
response.setHeader("Content-Disposition",
|
||||||
"attachment; filename=\"" + ReadExcel.encodeFileName(fileName, request) +"\"");
|
"attachment; filename=\"" + ReadExcel.encodeFileName(fileName, request) +"\"");
|
||||||
|
|||||||
+7
-59
@@ -10,6 +10,7 @@ import org.apache.poi.common.usermodel.HyperlinkType;
|
|||||||
import org.apache.poi.hssf.usermodel.*;
|
import org.apache.poi.hssf.usermodel.*;
|
||||||
import org.apache.poi.hssf.util.HSSFColor;
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -20,21 +21,13 @@ import java.io.*;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class HtmlTextExcel {
|
public class HtmlTextExcel {
|
||||||
|
|
||||||
public static String changeHtmlToExcel (HSSFSheet sheetItemsLeft,HSSFWorkbook wb, HttpServletRequest request, String itemContent, List<MarkTextVO> addList, List<MarkTextVO> delList) {
|
public static String changeHtmlToExcel (String itemContent, List<MarkTextVO> addList, List<MarkTextVO> delList) {
|
||||||
//超链接样式
|
|
||||||
Workbook workbook = new HSSFWorkbook();
|
|
||||||
CellStyle cellStyleLink =workbook.createCellStyle();
|
|
||||||
HSSFFont font = ((HSSFWorkbook) workbook).createFont();
|
|
||||||
font.setColor(HSSFColor.HSSFColorPredefined.LIGHT_BLUE.getIndex());
|
|
||||||
cellStyleLink.setFont(font);
|
|
||||||
cellStyleLink.setWrapText(true);
|
|
||||||
if (StringUtils.isNotEmpty(itemContent)) {
|
if (StringUtils.isNotEmpty(itemContent)) {
|
||||||
itemContent = itemContent.replaceAll("<div>","");
|
itemContent = itemContent.replaceAll("<div>","");
|
||||||
itemContent = itemContent.replaceAll("<div class=\"compareBackgroundColor\">","");
|
itemContent = itemContent.replaceAll("<div class=\"compareBackgroundColor\">","");
|
||||||
@@ -85,51 +78,6 @@ public class HtmlTextExcel {
|
|||||||
itemContent = itemContent.replaceAll("</span>","");
|
itemContent = itemContent.replaceAll("</span>","");
|
||||||
itemContent = itemContent.replaceAll("<span class=\"delClass\">","");
|
itemContent = itemContent.replaceAll("<span class=\"delClass\">","");
|
||||||
itemContent = itemContent.replaceAll("</span>","");
|
itemContent = itemContent.replaceAll("</span>","");
|
||||||
String rowDataAndPath = getSplitContent(request, itemContent);
|
|
||||||
// String dir = filePath + File.separator + UUID.randomUUID().toString().replace("-", "");
|
|
||||||
String sheetName = "对比结果";
|
|
||||||
Sheet sheet = workbook.createSheet(sheetName);
|
|
||||||
HSSFPatriarch patriarch = (HSSFPatriarch) sheet.createDrawingPatriarch();
|
|
||||||
String[] leftSplit = null;
|
|
||||||
leftSplit = rowDataAndPath.split("---");
|
|
||||||
int i = 1;
|
|
||||||
Row row = sheet.createRow(i);
|
|
||||||
if (leftSplit.length > 1) {
|
|
||||||
for (int j = 0; j < leftSplit.length; j++) {
|
|
||||||
if (ObjectUtils.isNotEmpty(leftSplit[j])) {
|
|
||||||
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
|
|
||||||
if (j > 0) {
|
|
||||||
Row row2 = sheet.getRow(j );
|
|
||||||
if (ObjectUtils.isEmpty(row2)) {
|
|
||||||
row2 = sheet.createRow(j);
|
|
||||||
}
|
|
||||||
log.info("-------------- 开始开始处理左侧图片、表格 -----------------");
|
|
||||||
try {
|
|
||||||
handleSpecificData(wb, patriarch, cellStyleLink, byteArrayOut, row2, i, j, leftSplit[j], 3);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
log.info("-------------- 左侧图片、表格 处理成功 -----------------");
|
|
||||||
} else {
|
|
||||||
log.info("-------------- 开始开始处理左侧图片、表格 -----------------");
|
|
||||||
try {
|
|
||||||
handleSpecificData(wb, patriarch, cellStyleLink, byteArrayOut, row, i, j, leftSplit[j], 3);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
log.info("-------------- 左侧图片、表格 处理成功 -----------------");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
List<SarFileCompareExcelMergeCell> mergeCells = new ArrayList<>();
|
|
||||||
SarFileCompareExcelMergeCell sarFileCompareExcelMergeCell = new SarFileCompareExcelMergeCell();
|
|
||||||
sarFileCompareExcelMergeCell.setLeftStart(i);
|
|
||||||
sarFileCompareExcelMergeCell.setLeftEnd(i + leftSplit.length - 1);
|
|
||||||
sarFileCompareExcelMergeCell.setRightStart(0);
|
|
||||||
sarFileCompareExcelMergeCell.setRightEnd(0);
|
|
||||||
mergeCells.add(sarFileCompareExcelMergeCell);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return itemContent;
|
return itemContent;
|
||||||
}
|
}
|
||||||
@@ -147,7 +95,7 @@ public class HtmlTextExcel {
|
|||||||
* @param cellNum
|
* @param cellNum
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private static void handleSpecificData(HSSFWorkbook workbook, HSSFPatriarch patriarch, CellStyle cellStyleLink, ByteArrayOutputStream byteArrayOut, Row row, int i, int j, String text, int cellNum) throws IOException {
|
public static void handleSpecificData(HSSFWorkbook workbook, HSSFPatriarch patriarch, CellStyle cellStyleLink, ByteArrayOutputStream byteArrayOut, Row row, int i, int j, String text, int cellNum) throws IOException {
|
||||||
if (text.contains("/upFiles")) {
|
if (text.contains("/upFiles")) {
|
||||||
String dir = "dcjd";
|
String dir = "dcjd";
|
||||||
row.setHeight((short) 3000); //设置行高
|
row.setHeight((short) 3000); //设置行高
|
||||||
@@ -261,7 +209,7 @@ public class HtmlTextExcel {
|
|||||||
* @param text
|
* @param text
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static String getSplitContent(HttpServletRequest request, String text) {
|
public static String getSplitContent(HttpServletRequest request, String text) {
|
||||||
text = text.replace("<p>", "").replace("</p>", "\r\n");
|
text = text.replace("<p>", "").replace("</p>", "\r\n");
|
||||||
//分割图片
|
//分割图片
|
||||||
log.info("-------------------------开始分割文字与图片---------------------------");
|
log.info("-------------------------开始分割文字与图片---------------------------");
|
||||||
@@ -281,7 +229,7 @@ public class HtmlTextExcel {
|
|||||||
* @param textAndImg
|
* @param textAndImg
|
||||||
* @param session
|
* @param session
|
||||||
*/
|
*/
|
||||||
private static void splitTable(String textAndImg,HttpSession session) {
|
public static void splitTable(String textAndImg, HttpSession session) {
|
||||||
if (textAndImg.contains("<replaceTable")) {
|
if (textAndImg.contains("<replaceTable")) {
|
||||||
String left = textAndImg.substring(0, textAndImg.indexOf("<replaceTable"));
|
String left = textAndImg.substring(0, textAndImg.indexOf("<replaceTable"));
|
||||||
String right = textAndImg.substring(textAndImg.indexOf("/replaceTable>") + 14);
|
String right = textAndImg.substring(textAndImg.indexOf("/replaceTable>") + 14);
|
||||||
@@ -300,7 +248,7 @@ public class HtmlTextExcel {
|
|||||||
* @param session
|
* @param session
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static void splitImg(String text, HttpSession session) {
|
public static void splitImg(String text, HttpSession session) {
|
||||||
if (text.contains("<img")) {
|
if (text.contains("<img")) {
|
||||||
String txtLeft = text.substring(0, text.indexOf("<img"));
|
String txtLeft = text.substring(0, text.indexOf("<img"));
|
||||||
String txtRight = text.substring(text.indexOf("g\">") + 3);
|
String txtRight = text.substring(text.indexOf("g\">") + 3);
|
||||||
|
|||||||
Reference in New Issue
Block a user