Browse Source

fix: 解决导出文件的超链接有多个时报错的问题

zhongwei
liwen 6 months ago
parent
commit
1350117761
  1. 5
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java
  2. 12
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java

5
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java

@ -161,7 +161,10 @@ public class RehearsalRecordServiceImpl extends ServiceImpl<RehearsalRecordMappe
}
} else {
// 添加空的ImageEntity,防止数据填入时显示"{{"
list.add(new ImageEntity());
ImageEntity imageEntity = new ImageEntity();
// 设置空字符串,防止空指针报错
imageEntity.setUrl("");
list.add(imageEntity);
}
rehearsalRecordDetailVO.setImages(list);
// 记录:换行符使用\r\n

12
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java

@ -128,18 +128,16 @@ public class BaseUtil {
for (int col = 0; col < table.getRow(row).getTableCells().size(); col++) {
XWPFTableCell cell = table.getRow(row).getCell(col);
for (XWPFParagraph p : cell.getParagraphs()) {
Iterator<XWPFRun> iterator = p.getRuns().iterator();
while (iterator.hasNext()) {
XWPFRun r = iterator.next();
String text = r.getText(0);
for (int index = 0; index < p.getRuns().size(); index++) {
XWPFRun run = p.getRuns().get(index);
String text = run.getText(0);
if (findText.equals(text)) {
r.setText("", 0); // 清除原有文本
XWPFParagraph paragraph = r.getParagraph();
run.setText("", 0); // 清除原有文本
XWPFParagraph paragraph = run.getParagraph();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String name = jsonObject.getString("name");
String url = jsonObject.getString("url");
url = URLEncoder.encode(url, "UTF-8");
String id = paragraph.getDocument().getPackagePart().addExternalRelationship(url, XWPFRelation.HYPERLINK.getRelation()).getId();
CTHyperlink cLink = paragraph.getCTP().addNewHyperlink();
cLink.setId(id);

Loading…
Cancel
Save