I want to create a hyperlink from a field 'Name' on Sheet1 (Summary) to the AutoFilter on column 'Name' on Sheet2 (Details), in order to display the details of that particular name only on the Sheet2.
I have imported :
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.CreationHelper;
Hyperlink to filter on other sheet.
I have done this using VB macro, but want to implement this using Java POI.
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..