文档对比图片bug
This commit is contained in:
+48
-101
@@ -278,57 +278,30 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
|||||||
leftSplit = rowDataAndPath.split("---");
|
leftSplit = rowDataAndPath.split("---");
|
||||||
if (leftSplit.length > 1) {
|
if (leftSplit.length > 1) {
|
||||||
for (int j = 0; j < leftSplit.length; j++) {
|
for (int j = 0; j < leftSplit.length; j++) {
|
||||||
if (j > 0) {
|
Row row2 = sheet.createRow(j + i);
|
||||||
Row row2 = sheet.createRow(j + i);
|
if (leftSplit[j].contains("/upFiles")) {
|
||||||
if (leftSplit[j].contains(".jpg") || leftSplit[j].contains(".png")) {
|
row2.setHeight((short) 5000); //设置行高
|
||||||
row2.setHeight((short) 5000); //设置行高
|
//先将图片下载到本地
|
||||||
//先将图片下载到本地
|
String fileLastName = leftSplit[j].substring(leftSplit[j].lastIndexOf("/") + 1);
|
||||||
String fileLastName = leftSplit[j].substring(leftSplit[j].lastIndexOf("/") + 1);
|
if (CosBootUtil.doesObjectExist(leftSplit[j])) {
|
||||||
if (CosBootUtil.doesObjectExist(leftSplit[j])) {
|
try (InputStream in = CosBootUtil.download(leftSplit[j])) {
|
||||||
try (InputStream in = CosBootUtil.download(leftSplit[j])) {
|
copyFile2(in, dir + File.separator + fileLastName);
|
||||||
copyFile2(in, dir + File.separator + fileLastName);
|
} catch (IOException e) {
|
||||||
} catch (IOException e) {
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
File file = new File(dir + File.separator + fileLastName);
|
}
|
||||||
if (file.exists()) {
|
File file = new File(dir + File.separator + fileLastName);
|
||||||
bufferImg = ImageIO.read(file);
|
if (file.exists()) {
|
||||||
ImageIO.write(bufferImg, "jpg", byteArrayOut);
|
bufferImg = ImageIO.read(file);
|
||||||
//anchor主要用于设置图片的属性
|
ImageIO.write(bufferImg, "jpg", byteArrayOut);
|
||||||
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 200, (short) 3, j + i, (short) 3, j + i);
|
//anchor主要用于设置图片的属性
|
||||||
patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
|
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 200, (short) 3, j + i, (short) 3, j + i);
|
||||||
|
patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
row2.createCell(3).setCellValue(leftSplit[j]);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (leftSplit[j].contains(".jpg") || leftSplit[j].contains(".png")) {
|
row2.createCell(3).setCellValue(leftSplit[j]);
|
||||||
row.setHeight((short) 5000); //设置行高
|
|
||||||
//先将图片下载到本地
|
|
||||||
String fileLastName = leftSplit[j].substring(leftSplit[j].lastIndexOf("/") + 1);
|
|
||||||
if (CosBootUtil.doesObjectExist(leftSplit[j])) {
|
|
||||||
try (InputStream in = CosBootUtil.download(leftSplit[j])) {
|
|
||||||
copyFile2(in, dir + File.separator + fileLastName);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File file = new File(dir + File.separator + fileLastName);
|
|
||||||
if (file.exists()) {
|
|
||||||
bufferImg = ImageIO.read(file);
|
|
||||||
ImageIO.write(bufferImg, "jpg", byteArrayOut);
|
|
||||||
//anchor主要用于设置图片的属性
|
|
||||||
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 200, (short) 3, j + i, (short) 3, j + i);
|
|
||||||
patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
row.createCell(3).setCellValue(leftSplit[j]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sarFileCompareExcelMergeCell.setLeftStart(i);
|
sarFileCompareExcelMergeCell.setLeftStart(i);
|
||||||
@@ -357,57 +330,30 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
|||||||
rightSplit = rowDataAndPath.split("---");
|
rightSplit = rowDataAndPath.split("---");
|
||||||
if (rightSplit.length > 1) {
|
if (rightSplit.length > 1) {
|
||||||
for (int j = 0; j < rightSplit.length; j++) {
|
for (int j = 0; j < rightSplit.length; j++) {
|
||||||
if (j > 0) {
|
Row row2 = sheet.createRow(j + i);
|
||||||
Row row2 = sheet.createRow(j + i);
|
if (rightSplit[j].contains("/upFiles")) {
|
||||||
if (rightSplit[j].contains(".jpg") || rightSplit[j].contains(".png")) {
|
row2.setHeight((short) 5000); //设置行高
|
||||||
row2.setHeight((short) 5000); //设置行高
|
//先将图片下载到本地
|
||||||
//先将图片下载到本地
|
String fileLastName = rightSplit[j].substring(rightSplit[j].lastIndexOf("/") + 1);
|
||||||
String fileLastName = rightSplit[j].substring(rightSplit[j].lastIndexOf("/") + 1);
|
if (CosBootUtil.doesObjectExist(rightSplit[j])) {
|
||||||
if (CosBootUtil.doesObjectExist(rightSplit[j])) {
|
try (InputStream in = CosBootUtil.download(rightSplit[j])) {
|
||||||
try (InputStream in = CosBootUtil.download(rightSplit[j])) {
|
copyFile2(in, dir + File.separator + fileLastName);
|
||||||
copyFile2(in, dir + File.separator + fileLastName);
|
} catch (IOException e) {
|
||||||
} catch (IOException e) {
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
File file = new File(dir + File.separator + fileLastName);
|
}
|
||||||
if (file.exists()) {
|
File file = new File(dir + File.separator + fileLastName);
|
||||||
bufferImg = ImageIO.read(file);
|
if (file.exists()) {
|
||||||
ImageIO.write(bufferImg, "jpg", byteArrayOut);
|
bufferImg = ImageIO.read(file);
|
||||||
//anchor主要用于设置图片的属性
|
ImageIO.write(bufferImg, "jpg", byteArrayOut);
|
||||||
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 200, (short) 3, j + i, (short) 3, j + i);
|
//anchor主要用于设置图片的属性
|
||||||
patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
|
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 200, (short) 7, j + i, (short) 7, j + i);
|
||||||
|
patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
row2.createCell(3).setCellValue(rightSplit[j]);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (rightSplit[j].contains(".jpg") || rightSplit[j].contains(".png")) {
|
row2.createCell(7).setCellValue(rightSplit[j]);
|
||||||
row.setHeight((short) 5000); //设置行高
|
|
||||||
//先将图片下载到本地
|
|
||||||
String fileLastName = rightSplit[j].substring(rightSplit[j].lastIndexOf("/") + 1);
|
|
||||||
if (CosBootUtil.doesObjectExist(rightSplit[j])) {
|
|
||||||
try (InputStream in = CosBootUtil.download(rightSplit[j])) {
|
|
||||||
copyFile2(in, dir + File.separator + fileLastName);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File file = new File(dir + File.separator + fileLastName);
|
|
||||||
if (file.exists()) {
|
|
||||||
bufferImg = ImageIO.read(file);
|
|
||||||
ImageIO.write(bufferImg, "jpg", byteArrayOut);
|
|
||||||
//anchor主要用于设置图片的属性
|
|
||||||
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 200, (short) 3, j + i, (short) 3, j + i);
|
|
||||||
patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
row.createCell(7).setCellValue(rightSplit[j]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sarFileCompareExcelMergeCell.setRightStart(i);
|
sarFileCompareExcelMergeCell.setRightStart(i);
|
||||||
@@ -443,7 +389,8 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
|||||||
row.getCell(1).setCellStyle(cellStyle);
|
row.getCell(1).setCellStyle(cellStyle);
|
||||||
}
|
}
|
||||||
if (ObjectUtils.isNotEmpty(mergeCells)) {
|
if (ObjectUtils.isNotEmpty(mergeCells)) {
|
||||||
for (SarFileCompareExcelMergeCell mergeCell : mergeCells) {
|
Set<SarFileCompareExcelMergeCell> mergeCellSet = new HashSet<>(mergeCells);
|
||||||
|
for (SarFileCompareExcelMergeCell mergeCell : mergeCellSet) {
|
||||||
Integer leftCount = mergeCell.getLeftEnd() - mergeCell.getLeftStart() + 1;
|
Integer leftCount = mergeCell.getLeftEnd() - mergeCell.getLeftStart() + 1;
|
||||||
Integer rightCount = mergeCell.getRightEnd() - mergeCell.getRightStart() + 1;
|
Integer rightCount = mergeCell.getRightEnd() - mergeCell.getRightStart() + 1;
|
||||||
Integer start = leftCount - rightCount >= 0 ? mergeCell.getLeftStart() : mergeCell.getRightStart();
|
Integer start = leftCount - rightCount >= 0 ? mergeCell.getLeftStart() : mergeCell.getRightStart();
|
||||||
@@ -461,7 +408,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
|||||||
sheet.addMergedRegion(region5);
|
sheet.addMergedRegion(region5);
|
||||||
CellRangeAddress region6 = new CellRangeAddress(start, end, 6, 6);
|
CellRangeAddress region6 = new CellRangeAddress(start, end, 6, 6);
|
||||||
sheet.addMergedRegion(region6);
|
sheet.addMergedRegion(region6);
|
||||||
CellRangeAddress region7 = new CellRangeAddress(start, end, 7, 7);
|
CellRangeAddress region7 = new CellRangeAddress(start, end, 8, 8);
|
||||||
sheet.addMergedRegion(region7);
|
sheet.addMergedRegion(region7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -487,11 +434,11 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private void addImgdata(String text,HttpSession session) {
|
private void addImgdata(String text,HttpSession session) {
|
||||||
if (text.contains("<") || text.contains(">")) {
|
if (text.contains("<img")) {
|
||||||
String txtLeft = text.substring(0, text.indexOf("<"));
|
String txtLeft = text.substring(0, text.indexOf("<img"));
|
||||||
String txtRight = text.substring(text.indexOf(">") + 1);
|
String txtRight = text.substring(text.indexOf("g\">") + 3);
|
||||||
String img = text.substring(text.indexOf("<"), text.indexOf(">"));
|
String img = text.substring(text.indexOf("<img"), text.indexOf("g\">"));
|
||||||
String path = img.substring(img.lastIndexOf("=") + 1, img.lastIndexOf("\""));
|
String path = img.substring(img.lastIndexOf("=") + 1)+"g";
|
||||||
text = txtLeft + "---" + path + "---" + txtRight;
|
text = txtLeft + "---" + path + "---" + txtRight;
|
||||||
addImgdata(text, session);
|
addImgdata(text, session);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user