文档对比图片bug
This commit is contained in:
+48
-101
@@ -278,57 +278,30 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
leftSplit = rowDataAndPath.split("---");
|
||||
if (leftSplit.length > 1) {
|
||||
for (int j = 0; j < leftSplit.length; j++) {
|
||||
if (j > 0) {
|
||||
Row row2 = sheet.createRow(j + i);
|
||||
if (leftSplit[j].contains(".jpg") || leftSplit[j].contains(".png")) {
|
||||
row2.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);
|
||||
}
|
||||
Row row2 = sheet.createRow(j + i);
|
||||
if (leftSplit[j].contains("/upFiles")) {
|
||||
row2.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));
|
||||
}
|
||||
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 {
|
||||
row2.createCell(3).setCellValue(leftSplit[j]);
|
||||
}
|
||||
} else {
|
||||
if (leftSplit[j].contains(".jpg") || leftSplit[j].contains(".png")) {
|
||||
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]);
|
||||
}
|
||||
row2.createCell(3).setCellValue(leftSplit[j]);
|
||||
}
|
||||
}
|
||||
sarFileCompareExcelMergeCell.setLeftStart(i);
|
||||
@@ -357,57 +330,30 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
rightSplit = rowDataAndPath.split("---");
|
||||
if (rightSplit.length > 1) {
|
||||
for (int j = 0; j < rightSplit.length; j++) {
|
||||
if (j > 0) {
|
||||
Row row2 = sheet.createRow(j + i);
|
||||
if (rightSplit[j].contains(".jpg") || rightSplit[j].contains(".png")) {
|
||||
row2.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);
|
||||
}
|
||||
Row row2 = sheet.createRow(j + i);
|
||||
if (rightSplit[j].contains("/upFiles")) {
|
||||
row2.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));
|
||||
}
|
||||
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) 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 {
|
||||
if (rightSplit[j].contains(".jpg") || rightSplit[j].contains(".png")) {
|
||||
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]);
|
||||
}
|
||||
row2.createCell(7).setCellValue(rightSplit[j]);
|
||||
}
|
||||
}
|
||||
sarFileCompareExcelMergeCell.setRightStart(i);
|
||||
@@ -443,7 +389,8 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
row.getCell(1).setCellStyle(cellStyle);
|
||||
}
|
||||
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 rightCount = mergeCell.getRightEnd() - mergeCell.getRightStart() + 1;
|
||||
Integer start = leftCount - rightCount >= 0 ? mergeCell.getLeftStart() : mergeCell.getRightStart();
|
||||
@@ -461,7 +408,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
sheet.addMergedRegion(region5);
|
||||
CellRangeAddress region6 = new CellRangeAddress(start, end, 6, 6);
|
||||
sheet.addMergedRegion(region6);
|
||||
CellRangeAddress region7 = new CellRangeAddress(start, end, 7, 7);
|
||||
CellRangeAddress region7 = new CellRangeAddress(start, end, 8, 8);
|
||||
sheet.addMergedRegion(region7);
|
||||
}
|
||||
}
|
||||
@@ -487,11 +434,11 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
* @return
|
||||
*/
|
||||
private void addImgdata(String text,HttpSession session) {
|
||||
if (text.contains("<") || text.contains(">")) {
|
||||
String txtLeft = text.substring(0, text.indexOf("<"));
|
||||
String txtRight = text.substring(text.indexOf(">") + 1);
|
||||
String img = text.substring(text.indexOf("<"), text.indexOf(">"));
|
||||
String path = img.substring(img.lastIndexOf("=") + 1, img.lastIndexOf("\""));
|
||||
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);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user