|
|
@ -128,19 +128,22 @@ public class BaseUtil { |
|
|
|
for (int col = 0; col < table.getRow(row).getTableCells().size(); col++) { |
|
|
|
for (int col = 0; col < table.getRow(row).getTableCells().size(); col++) { |
|
|
|
XWPFTableCell cell = table.getRow(row).getCell(col); |
|
|
|
XWPFTableCell cell = table.getRow(row).getCell(col); |
|
|
|
for (XWPFParagraph p : cell.getParagraphs()) { |
|
|
|
for (XWPFParagraph p : cell.getParagraphs()) { |
|
|
|
Iterator<XWPFRun> iterator = p.getRuns().iterator(); |
|
|
|
for (int index = 0; index < p.getRuns().size(); index++) { |
|
|
|
while (iterator.hasNext()) { |
|
|
|
XWPFRun run = p.getRuns().get(index); |
|
|
|
XWPFRun r = iterator.next(); |
|
|
|
String text = run.getText(0); |
|
|
|
String text = r.getText(0); |
|
|
|
|
|
|
|
if (findText.equals(text)) { |
|
|
|
if (findText.equals(text)) { |
|
|
|
r.setText("", 0); // 清除原有文本
|
|
|
|
run.setText("", 0); // 清除原有文本
|
|
|
|
XWPFParagraph paragraph = r.getParagraph(); |
|
|
|
XWPFParagraph paragraph = run.getParagraph(); |
|
|
|
for (int i = 0; i < jsonArray.length(); i++) { |
|
|
|
for (int i = 0; i < jsonArray.length(); i++) { |
|
|
|
JSONObject jsonObject = jsonArray.getJSONObject(i); |
|
|
|
JSONObject jsonObject = jsonArray.getJSONObject(i); |
|
|
|
String name = jsonObject.getString("name"); |
|
|
|
String name = jsonObject.getString("name"); |
|
|
|
String url = jsonObject.getString("url"); |
|
|
|
String url = jsonObject.getString("url"); |
|
|
|
url = URLEncoder.encode(url, "UTF-8"); |
|
|
|
// url编码格式化
|
|
|
|
String id = paragraph.getDocument().getPackagePart().addExternalRelationship(url, XWPFRelation.HYPERLINK.getRelation()).getId(); |
|
|
|
String encodeName = URLEncoder.encode(name, "UTF-8").replaceAll("\\+", "%20"); |
|
|
|
|
|
|
|
String prefixString = url.substring(0, url.lastIndexOf("/") + 1); |
|
|
|
|
|
|
|
String encodeUrl = prefixString + encodeName; |
|
|
|
|
|
|
|
String id = paragraph.getDocument().getPackagePart().addExternalRelationship(encodeUrl, |
|
|
|
|
|
|
|
XWPFRelation.HYPERLINK.getRelation()).getId(); |
|
|
|
CTHyperlink cLink = paragraph.getCTP().addNewHyperlink(); |
|
|
|
CTHyperlink cLink = paragraph.getCTP().addNewHyperlink(); |
|
|
|
cLink.setId(id); |
|
|
|
cLink.setId(id); |
|
|
|
CTText ctText = CTText.Factory.newInstance(); |
|
|
|
CTText ctText = CTText.Factory.newInstance(); |
|
|
|