在Apache的POI多个超链接 [英] Multiple Hyperlinks in Apache POI

查看:714
本文介绍了在Apache的POI多个超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能同一个超链接多次在一个Excel工作表?

Is it possible to have same hyperlink multiple times in a single excel sheet?

Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
link.setAddress("http://poi.apache.org/");

我已经使用了上述code创建超链接及以下code生成Excel表格的行和列。

I have used the above code for creating the hyperlink and the following code to generate the rows and columns for the excel sheet.

 Row title = null;
 Cell reportNames = null;

   /*
       I am processing some queries here
   */


      while(rs.next()){
            title = sheet.createRow(idx); 
            reportNames = title.createCell(0);
            reportNames.setCellValue(rs.getString(1));
            reportNames.setHyperlink(link); 
            idx++;
            sheet.autoSizeColumn(0);

          }
        }

我的问题是显示超链接/只针对最后一行的内容。我的意思是,只有最后一排是可以点击的,它正确地重定向我哪里像别人都没有设置超链接?
是否有任何限制,这样只能有一个超链接指向同一网址是什么?还是我做错了什么?

My problem is the hyperlink is displayed/works only for the content of last row. I mean, only the last row is clickable and it redirects me properly where as the others are not set as hyperlinks? Is there any restriction such that there can be only one hyperlink pointing to the same web address? Or am I doing anything wrong?

推荐答案

您必须要创建一个超链接的单元格,每次创建新的超链接对象。当你调用setHyperlink Cell对象上,它为超链接到自身的引用。下面是从 org.apache.poi.xssf.usermodel.XSSFCell 类(行913 - 921 3.9版)的摘录:

You must create a new Hyperlink object every time you want to create a hyperlinked cell. When you call setHyperlink on the Cell object, it sets a reference to itself for a hyperlink. Here's an extract from the org.apache.poi.xssf.usermodel.XSSFCell class (lines 913 - 921 in version 3.9):

public void setHyperlink(Hyperlink hyperlink) {
    XSSFHyperlink link = (XSSFHyperlink)hyperlink;

    // Assign to us
    link.setCellReference( new CellReference(_row.getRowNum(), _cellNum).formatAsString() );

    // Add to the lists
    getSheet().addHyperlink(link);
}

它通过查看 link.setCellReference变得明显(... 方法调用。

这篇关于在Apache的POI多个超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆