Reputation: 1985
I need to generate an excel report using java. So I'm planning to use Apache POI.
But there is one required which I'm not sure if its possible through apache POI.
Requesting you to please help me with this.
Requirement:
Excel doc should have multiple sheets say sheet1 and sheet 2.
sheet1 will be having multiple links.
sheet2 will be having 100's of columns.
Each link in sheet1 should be linked to one of the column of sheet2.
When user clicks on any of these links, it should take user to sheet2 and automatically focus on that column.
For ex. If user clicks on link pointing to 95th column of sheet2, then clicking on that link should open sheet2 and 95th column should be in focus.
Please let me know if its feasible. I searched through net but couldn't find any way of doing it.
Any pointer is really appreciated.
Upvotes: 3
Views: 11031
Reputation: 188
Well, I think you could use Hyperlinks to Sheet cells(if not columns) in the same document. http://poi.apache.org/spreadsheet/quick-guide.html#Hyperlinks
Following is an sample extracted from above link-
To create links you could do something like:
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
Cell cell;
Sheet sheet = wb.createSheet("Hyperlinks");
//URL
cell = sheet.createRow(0).createCell((short)0);
cell.setCellValue("Worksheet Link");
Hyperlink link2 = createHelper.createHyperlink(Hyperlink.LINK_DOCUMENT);
link2.setAddress("'Target Sheet'!A1");
cell.setHyperlink(link2);
cell.setCellStyle(hlink_style);
This will take you to a sheet named 'Target Sheet' and then to cell A1
Upvotes: 15