List of usage examples for org.apache.poi.ss.usermodel Hyperlink setAddress
public void setAddress(String address);
From source file:bad.robot.excel.cell.HyperlinkCell.java
License:Apache License
private Hyperlink createHyperlink(Workbook workbook) { Hyperlink hyperlink = workbook.getCreationHelper().createHyperlink(LINK_URL); hyperlink.setAddress(link.toExternalForm()); return hyperlink; }
From source file:com.b2international.snowowl.datastore.server.importer.AbstractTerminologyExcelExporter.java
License:Apache License
/** * Creates the index sheet based on the given sheet names. * // w ww . ja v a2 s .c om * @param sheetNames */ protected void createIndexSheet(final Collection<T> components) { final Sheet indexSheet = workbook.createSheet("INDEX"); final List<T> filteredComponents = Lists.newArrayList(Iterables.filter(components, new Predicate<T>() { @Override public boolean apply(T input) { return isToExport(getComponentId(input)); } })); final List<String> sheetNames = extractSheetNamesFromTerminologyComponents(filteredComponents); final Row firstRow = indexSheet.createRow(0); createCell(firstRow, getIndexSheetHeaderName(), BOLD_STYLE, 0); for (int i = 0; i < sheetNames.size(); i++) { final String sheetName = getFinalSheetName(i + 1, sheetNames.get(i)); final Hyperlink hyperlink = workbook.getCreationHelper().createHyperlink(XSSFHyperlink.LINK_DOCUMENT); hyperlink.setLabel(sheetName); hyperlink.setAddress(String.format("'%s'!A1", sheetName)); final Row row = indexSheet.createRow(i + 1); final Cell cell = row.createCell(0); cell.setCellValue(sheetName); cell.setCellStyle(hyperlinkStyle); cell.setHyperlink(hyperlink); } indexSheet.autoSizeColumn(0); }
From source file:com.blackducksoftware.tools.commonframework.standard.datatable.writer.DataSetWriterExcel.java
License:Apache License
private void populateHyperlinkCell(Record record, FieldDef fieldDef, Cell cell) throws Exception { String cellValue = record.getHyperlinkFieldValue(fieldDef.getName()).getDisplayText(); cell.setCellValue(cellValue);/*ww w.j a v a2 s . c o m*/ // cell style for hyperlinks // by default hyperlinks are blue and underlined CellStyle hlink_style = workbook.createCellStyle(); Font hlink_font = workbook.createFont(); hlink_font.setUnderline(Font.U_SINGLE); hlink_font.setColor(IndexedColors.BLUE.getIndex()); hlink_style.setFont(hlink_font); // Make it a hyperlink CreationHelper createHelper = workbook.getCreationHelper(); Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL); link.setAddress(record.getHyperlinkFieldValue(fieldDef.getName()).getHyperlinkText()); cell.setHyperlink(link); cell.setCellStyle(hlink_style); }
From source file:com.hp.amss.util.HyperlinkExample.java
License:Apache License
public static void main(String[] args) throws Exception { Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); //cell style for hyperlinks //by default hyperlinks are blue and underlined CellStyle hlink_style = wb.createCellStyle(); Font hlink_font = wb.createFont(); hlink_font.setUnderline(Font.U_SINGLE); hlink_font.setColor(IndexedColors.BLUE.getIndex()); hlink_style.setFont(hlink_font);//from www . java2 s.c o m Cell cell; Sheet sheet = wb.createSheet("Hyperlinks"); //URL cell = sheet.createRow(0).createCell((short) 0); cell.setCellValue("URL Link"); Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL); link.setAddress("http://poi.apache.org/"); cell.setHyperlink(link); cell.setCellStyle(hlink_style); //link to a file in the current directory cell = sheet.createRow(1).createCell((short) 0); cell.setCellValue("File Link"); link = createHelper.createHyperlink(Hyperlink.LINK_FILE); link.setAddress("link1.xls"); cell.setHyperlink(link); cell.setCellStyle(hlink_style); //e-mail link cell = sheet.createRow(2).createCell((short) 0); cell.setCellValue("Email Link"); link = createHelper.createHyperlink(Hyperlink.LINK_EMAIL); //note, if subject contains white spaces, make sure they are url-encoded link.setAddress("mailto:poi@apache.org?subject=Hyperlinks"); cell.setHyperlink(link); cell.setCellStyle(hlink_style); //TODO cell.setCellValue(createHelper.createRichTextString("")); cell.setCellType(Cell.CELL_TYPE_STRING); //link to a place in this workbook //create a target sheet and cell Sheet sheet2 = wb.createSheet("Target Sheet"); sheet2.createRow(0).createCell((short) 0).setCellValue("Target Cell"); cell = sheet.createRow(3).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); FileOutputStream out = new FileOutputStream("C:\\hyperinks.xlsx"); wb.write(out); out.close(); }
From source file:com.sec.ose.osi.report.standard.IdentifiedFilesSheetTemplate.java
License:Open Source License
public void writeRow(ArrayList<IdentifiedFilesRow> identifiedFilesRowList) { for (IdentifiedFilesRow identifiedFilesRow : identifiedFilesRowList) { Row row = sheet.createRow(curRow++); Cell cell = row.createCell(ISheetTemplate.COL_A); cell.setCellValue(identifiedFilesRow.getProjectName()); cell.setCellStyle(normalStyle);// ww w . j a v a 2 s. c om cell = row.createCell(ISheetTemplate.COL_B); cell.setCellValue(identifiedFilesRow.getFullPath()); cell.setCellStyle(leftStyle); cell = row.createCell(ISheetTemplate.COL_C); cell.setCellValue(identifiedFilesRow.getComponent()); cell.setCellStyle(normalStyle); cell = row.createCell(ISheetTemplate.COL_D); cell.setCellValue(identifiedFilesRow.getLicense()); cell.setCellStyle(normalStyle); cell = row.createCell(ISheetTemplate.COL_E); cell.setCellValue(identifiedFilesRow.getDiscoveryType()); cell.setCellStyle(normalStyle); cell = row.createCell(ISheetTemplate.COL_F); cell.setCellStyle(normalStyle); String value = ""; String url = identifiedFilesRow.getUrl(); if (url != null && (url.length() != 0) && !"null".equals(url)) { Hyperlink link = wb.getCreationHelper().createHyperlink(Hyperlink.LINK_URL); link.setAddress(url); link.setLabel(url); cell.setHyperlink(link); cell.setCellStyle(getCellStyle(WHITE, getFont(BLUE, (short) 10, false))); value = "Show Matched Code (" + (identifiedFilesRow.getCodeMatchCnt()) + ")"; } cell.setCellValue(value); cell = row.createCell(ISheetTemplate.COL_G); cell.setCellValue(identifiedFilesRow.getComment()); cell.setCellStyle(leftStyle); } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.export.template.DataExportIntroSheetGenerator.java
License:Open Source License
/** * Creates a section of the summary, containing links to one of the types of sheets * /*from w w w . j a v a 2 s. com*/ * @param sheetContexts list of sheets to link to. Only contains one type of {@link NamedExpression} * @param startAt the row to start at in the introduction sheet * @param sectionHeader the header of the section * * @return the row number that was reached while inserting the links */ private int createSummarySection(List<SheetContext> sheetContexts, int startAt, String sectionHeader) { int rowNr = startAt; Map<IteraExcelStyle, CellStyle> styles = wbContext.getStyles(); Workbook workbook = wbContext.getWb(); CreationHelper createHelper = workbook.getCreationHelper(); // header Sheet introSheet = getIntroductionSheet(); Cell headerCell = introSheet.createRow(rowNr++).createCell(SUMMARY_COL); headerCell.setCellValue(sectionHeader); headerCell.setCellStyle(styles.get(IteraExcelStyle.HEADER)); headerCell.getRow().createCell(SUMMARY_COL + 1).setCellStyle(styles.get(IteraExcelStyle.HEADER)); for (SheetContext sheetContext : sheetContexts) { String sheetName = sheetContext.getSheetName(); String extraInfo = sheetContext.getExpression().getName(); // name is empty, we assume it's a relationship, we need to get the name of the relationship ends if (StringUtils.isEmpty(extraInfo)) { NamedExpression expression = sheetContext.getExpression(); if (expression instanceof RelationshipExpression) { extraInfo = createRelationshipExtrainfo((RelationshipExpression) expression); } } Row entryRow = introSheet.createRow(rowNr++); Cell hyperlinkCell = entryRow.createCell(SUMMARY_COL); hyperlinkCell.setCellValue(sheetName); entryRow.createCell(SUMMARY_COL + 1).setCellValue(extraInfo); Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_DOCUMENT); link.setAddress("'" + sheetName + "'!A1"); hyperlinkCell.setHyperlink(link); hyperlinkCell.setCellStyle(styles.get(IteraExcelStyle.HYPERLINK)); } //spacing between sections introSheet.createRow(rowNr++); return rowNr; }
From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.export.template.RelationshipSheetGenerator.java
License:Open Source License
/**{@inheritDoc}**/ protected void addHeaderHyperlink(FeatureExpression<?> featureExpression, Cell headerCell) { Hyperlink link = wbContext.getWb().getCreationHelper().createHyperlink(Hyperlink.LINK_DOCUMENT); String sheetName = wbContext//from w w w. j a v a 2 s . c o m .getSheetContextByExpressionName(featureExpression.getType().getPersistentName()).getSheetName(); link.setAddress("'" + sheetName + "'!A1"); headerCell.setHyperlink(link); }
From source file:de.iteratec.iteraplan.businesslogic.exchange.legacyExcel.exporter.ExportWorkbook.java
License:Open Source License
/** * Creates a hyperlink from a <code>url</code>. * /*from ww w . j a v a 2 s .co m*/ * @param url * @return a hyperlink to the <code>url</code>or <code>null</code> if url is null */ private Hyperlink createHyperlink(String url) { if (url == null) { return null; } CreationHelper createHelper = this.getWb().getCreationHelper(); Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL); link.setAddress(url); return link; }
From source file:de.iteratec.iteraplan.businesslogic.exchange.timeseriesExcel.exporter.TimeseriesIntroSheetGenerator.java
License:Open Source License
@Override protected void createSummary() { Sheet introSheet = getIntroductionSheet(); int rowNum = SUMMARY_ROW; Cell headerCell = introSheet.createRow(rowNum++).createCell(SUMMARY_COL); headerCell.setCellValue(MessageAccess.getStringOrNull("excel.export.timeseries.intro.description")); headerCell.setCellStyle(wbContext.getCellStyles().get(IteraExcelStyle.HEADER)); introSheet.addMergedRegion(new CellRangeAddress(headerCell.getRowIndex(), headerCell.getRowIndex(), headerCell.getColumnIndex(), headerCell.getColumnIndex() + 1)); CreationHelper createHelper = getWorkbook().getCreationHelper(); // TODO group the summary by building block type with subheaders for (int i = 0; i < getWorkbook().getNumberOfSheets(); i++) { Sheet sheet = getWorkbook().getSheetAt(i); String sheetName = sheet.getSheetName(); if (!introSheet.equals(sheet)) { Row summaryRow = introSheet.createRow(rowNum++); Cell hyperlinkCell = summaryRow.createCell(SUMMARY_COL); hyperlinkCell.setCellValue(sheetName); summaryRow.createCell(SUMMARY_COL + 1) .setCellValue(ExcelUtils.getStringCellValue(sheet.getRow(0).getCell(0))); Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_DOCUMENT); link.setAddress("'" + sheetName + "'!A1"); hyperlinkCell.setHyperlink(link); hyperlinkCell.setCellStyle(wbContext.getCellStyles().get(IteraExcelStyle.HYPERLINK)); }/*from w ww. j a va 2 s .c o m*/ } adjustSheetColumnWidths(); }
From source file:de.jlo.talendcomp.excel.SpreadsheetOutput.java
License:Apache License
private void setCellHyperLink(Cell cell, String url) { if (url.contains("://")) { Hyperlink link = creationHelper.createHyperlink(HyperlinkType.URL); link.setAddress(url); cell.setHyperlink(link);/*ww w .ja v a2 s .c om*/ } else if (url.startsWith("mailto:")) { Hyperlink link = creationHelper.createHyperlink(HyperlinkType.EMAIL); link.setAddress(url); cell.setHyperlink(link); } else { Hyperlink link = creationHelper.createHyperlink(HyperlinkType.FILE); link.setAddress(url); cell.setHyperlink(link); } if (cell.getCellTypeEnum() == CellType.BLANK) { cell.setCellValue(url); } }