/** * セルにハイパーリンクを設定する。 * * @param cell セル * @param type リンクタイプ * @param address ハイパーリンクアドレス * @see org.apache.poi.common.usermodel.Hyperlink */ public static void setHyperlink( Cell cell, HyperlinkType hyperlinkType, String address) { Workbook wb = cell.getRow().getSheet().getWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); Hyperlink link = createHelper.createHyperlink( hyperlinkType); if ( link instanceof HSSFHyperlink) { (( HSSFHyperlink) link).setTextMark( address); } else if ( link instanceof XSSFHyperlink) { (( XSSFHyperlink) link).setAddress( address); } cell.setHyperlink( link); }
public void createLinkCell(HSSFCell cell, String value, String target, boolean bordered) { cell.setCellValue(value); final HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT); link.setAddress("'" + normalizeAsLink(target) + "'!A1"); cell.setHyperlink(link); if (bordered) { cell.setCellStyle(borderedLinkStyle); } else { cell.setCellStyle(linkStyle); } }
/** * Create a HSSFCell in row with hyperlink, index and value. * * @param row HSSFRow * @param index int * @param value String * @param url String * @return HSSFCell */ public static HSSFCell createCell(HSSFRow row, int index, HSSFCellStyle cellStyle, String value, String url) { HSSFCell cell = createCell(row, index, value); HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL); link.setAddress(url); cell.setHyperlink(link); cell.setCellStyle(cellStyle); return cell; }
private void criarBodyXLS(HSSFWorkbook wb, HSSFSheet sheet, int numLinha, PessoaVO pessoa, Set<DadosRetInstVO> listResultados) { DadosXLSService service = new DadosXLSService(); service.prepareBody(pessoa, listResultados); List<Column> listBody = service.getValuesBody(); HSSFRow row = sheet.createRow(numLinha); // tipo de validacao na coluna 0. int i = 0; for(Column value: listBody) { if(value instanceof ColumnLink) { // cria o link na planilha HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL); String url = urlPaginaRetorno + NOME_SERVLET + value.getValue(); link.setAddress(url); HSSFCell cellLink = row.createCell(i++); cellLink.setHyperlink(link); ColumnLink columnLink = (ColumnLink) value; cellLink.setCellValue(new HSSFRichTextString(columnLink.getTextoLink())); } else { row.createCell(i++, HSSFCell.CELL_TYPE_STRING).setCellValue(new HSSFRichTextString(value.getValue())); } } // preenchimento da folha de estilo. do mesmo tamanho do cabecalho. for (int numColuna = 0; numColuna < listBody.size(); numColuna++) { row.getCell(numColuna).setCellStyle(estiloDadosRetorno(wb)); int tamanhoColuna = row.getCell(numColuna).getRichStringCellValue().getString().length(); autoSizing(sheet, numColuna, tamanhoColuna); } }