美文网首页
POI设置超链接

POI设置超链接

作者: 小灰灰_加油 | 来源:发表于2018-04-25 20:59 被阅读0次
    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();
        }
    
    }

    相关文章

      网友评论

          本文标题:POI设置超链接

          本文链接:https://www.haomeiwen.com/subject/ekujkftx.html