Java 将超链接插入XWPFTableRow
我无法使用XWPFTableRow在单元格中插入指向其他文档的超链接Java 将超链接插入XWPFTableRow,java,hyperlink,apache-poi,tablerow,settext,Java,Hyperlink,Apache Poi,Tablerow,Settext,我无法使用XWPFTableRow在单元格中插入指向其他文档的超链接 XWPFTableRow tableRow = table.createRow(); //Nombre GUI / Botón tableRow.getCell(0).setColor(cellColorImPar); tableRow.getCell(0).setText("Añadir"); //Estado tableRow.getCell(1).setColor(cell
XWPFTableRow tableRow = table.createRow();
//Nombre GUI / Botón
tableRow.getCell(0).setColor(cellColorImPar);
tableRow.getCell(0).setText("Añadir");
//Estado
tableRow.getCell(1).setColor(cellColorImPar);
tableRow.getCell(1).setText("Service: [entidad].rest.be#add");
我想转换超链接中的文本
谢谢,对不起。我只想将文本服务:[entidad].rest.beadd转换为超链接 我的最终解决办法是:
//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});
}
我在你的代码片段中看不到任何处理超链接的代码。您正在尝试哪些代码不起作用?