您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何以POI Word格式创建电子邮件链接

如何以POI Word格式创建电子邮件链接

public void example() throws Exception{

        XWPFDocument document = new XWPFDocument(); 
        //Append a link to 
        appendExternalHyperlink("https://poi.apache.org", " Link to POI", document.createParagraph());

        document.write(new FileOutputStream("resultat.docx"));
    }

    /**
     * Appends an external hyperlink to the paragraph.
     * 
     * @param url The URL to the external target
     * @param text The linked text
     * @param paragraph the paragraph the link will be appended to.
     */
    public static void appendExternalHyperlink(String url, String text, XWPFParagraph paragraph){

        //Add the link as External relationship
        String id=paragraph.getDocument().getPackagePart().addExternalRelationship(url, XWPFRelation.HYPERLINK.getRelation()).getId();

        //Append the link and bind it to the relationship
        CTHyperlink cLink=paragraph.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});

        //Insert the linked text into the link
        cLink.setRArray(new CTR[]{ctr});
    }
其他 2022/1/1 18:32:27 有391人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶