對不起。我只是想轉換的文本「服務:entidad] .rest.be#添加」,在一個超鏈接
我最後的解決辦法是:
//Fila 1 - Añadir
XWPFTableRow tableRow = table.createRow();
//Nombre GUI/Botón
tableRow.getCell(0).setColor(cellColorImPar);
tableRow.getCell(0).setText("Añadir");
tableRow.getCell(1).setColor(cellColorImPar);
XWPFParagraph para1 = tableRow.getCell(1).getParagraphs().get(0);
para1.setAlignment(ParagraphAlignment.LEFT);
XWPFRun run1 = para1.createRun();
run1.setText("Habilitar el botón si tiene ROLE de MODIFICACION");
run1.addBreak();
run1 = para1.createRun();
appendExternalHyperlink("../Servicios/"+name+"_Service.docx","1. Servicio del botón guardar: "+prepareName+".rest.be#add",run1);
run1.addBreak();
public static void appendExternalHyperlink(String url, String text, XWPFRun run){
//Add the link as External relationship
String id=run.getDocument().getPackagePart().addExternalRelationship(url, XWPFRelation.HYPERLINK.getRelation()).getId();
//Append the link and bind it to the relationship
CTHyperlink cLink=run.getParagraph().getCTP().addNewHyperlink();
cLink.setId(id);
//Create the linked text
CTText ctText=CTText.Factory.newInstance();
ctText.setStringValue(text);
CTR ctr=CTR.Factory.newInstance();
ctr.setTArray(new CTText[]{ctText});
//Create the formatting
CTRPr rpr = ctr.addNewRPr();
CTColor colour = CTColor.Factory.newInstance();
colour.setVal("0000FF");
rpr.setColor(colour);
CTRPr rpr1 = ctr.addNewRPr();
rpr1.addNewU().setVal(STUnderline.SINGLE);
//Insert the linked text into the link
cLink.setRArray(new CTR[]{ctr});
}
我看不到任何代碼處理中的超鏈接片段。你試過哪些代碼不起作用? – Gagravarr