How to create hyperlink to a filter on other sheet using Apache poi in Java?

主宰稳场 提交于 2019-12-07 15:30:37

I had troubles with Hyperlinks some time ago, and the quickest way to do that (I was in a hurry too!) is the following:

row.createCell(cellIdx, HSSFCell.CELL_TYPE_FORMULA).setCellFormula(String.format("HYPERLINK(%s; \"%s\")", sheetAndCellLocation, friendlyText));

To insert hyperlink into cell in Excel sheet using Apache POI we need CreationHelper, we need to get CreationHelper from WorkBook (like XSSFWorkBook). Code snippet:

CreationHelper creationHelper = getWorkbook().getCreationHelper();
Hyperlink link = creationHelper.createHyperlink(Hyperlink.LINK_URL);
link.setAddress("www.google.com");

There are other types of HyperLink available in Apache POI one of them is LINK_URL. also we can apply style to hyperlink created by default it will be blue and underlined.

XSSFCellStyle hLinkStyle = getWorkbook().createCellStyle();
Font hLinkFont = getWorkbook().createFont();
hLinkFont.setFontName("Ariel");
hLinkFont.setUnderline(Font.U_SINGLE);
hLinkFont.setColor(IndexedColors.BLUE.getIndex() );
hLinkStyle.setFont(hLinkFont);

Not supported with JAVA POI - Till what I found..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!