POI设置超链接

public void testSetHyperLink() {
    XSSFWorkbook workbook = new XSSFWorkbook();
    try {
        FileOutputStream out = new FileOutputStream("d:\\testSetHyperLink.xlsx");
        XSSFSheet sheet = workbook.createSheet("1");
        XSSFCellStyle style = workbook.createCellStyle();
        XSSFFont font = workbook.createFont();
        font.setUnderline(XSSFFont.U_DOUBLE);
        font.setColor(IndexedColors.RED.getIndex());
        style.setFont(font);


        CreationHelper createHelper = workbook.getCreationHelper();

        XSSFCellStyle cellStyle = workbook.createCellStyle();
        XSSFRow row = sheet.createRow(0);
        XSSFCell cell = row.createCell(0);
        cell.setCellValue("杨晨辉的单词表.xlsx");
        XSSFFont font1 = workbook.createFont();
        font1.setColor(HSSFColor.GREEN.index);
        cellStyle.setFont(font1);
        cell.setCellStyle(cellStyle);

        Hyperlink hyperlink = createHelper.createHyperlink(Hyperlink.LINK_FILE);
        hyperlink.setAddress("C://Users//Administrator//Desktop//杨晨辉的单词表.xlsx");
        cell.setHyperlink(hyperlink);
        workbook.write(out);
        out.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容