poi连接跳转到对应的sheet

poi版本依赖如下

  <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>4.1.2</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>4.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-scratchpad</artifactId>
        <version>4.1.2</version>
    </dependency>

话不多说代码如下

 HSSFWorkbook wb = new HSSFWorkbook();
        /* 建立新的sheet对象*/
        HSSFSheet sheet = wb.createSheet("汇总页面");
        HSSFRow row = sheet.createRow((short)0);
        /* 连接跳转*/
        CreationHelper createHelper = wb.getCreationHelper();
        HSSFCell likeCell = row.createCell((short)0);
        Hyperlink hyperlink = createHelper.createHyperlink(HyperlinkType.DOCUMENT);
        // "#"表示本文档    "明细页面"表示sheet页名称  "A10"表示第几列第几行
        hyperlink.setAddress("#明细页面!A10");
        likeCell.setHyperlink(hyperlink);
        // 点击进行跳转
        likeCell.setCellValue("dddd");
        /* 设置为超链接的样式*/
        HSSFCellStyle linkStyle = wb.createCellStyle();
        HSSFFont cellFont= wb.createFont();
        cellFont.setUnderline((byte) 1);
        linkStyle.setFont(cellFont);
        likeCell.setCellStyle(linkStyle);
        /* 建立第二个sheet对象*/
        HSSFSheet sheet2 = wb.createSheet("明细页面");  //建立新的sheet对象
        for (int i = 0; i < 30; i++) {
            HSSFRow row2 = sheet2.createRow((short)i);
            HSSFCell cell2 = row2.createCell((short)0);
            cell2.setCellValue("测试第"+(i+1)+"行");
        }
        /* 输出文件*/
        FileOutputStream fileOut = new FileOutputStream("D:\\汇总和明细.xls");
        wb.write(fileOut);
        fileOut.close();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值