Example usage for org.apache.poi.ss.usermodel Hyperlink setLabel

List of usage examples for org.apache.poi.ss.usermodel Hyperlink setLabel

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Hyperlink setLabel.

Prototype

public void setLabel(String label);

Source Link

Document

Sets text label for this hyperlink

Usage

From source file:com.b2international.snowowl.datastore.server.importer.AbstractTerminologyExcelExporter.java

License:Apache License

/**
 * Creates the index sheet based on the given sheet names.
 * //from   w  w w .j a  va  2 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.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);// www .j  a v  a2 s. c  o m

        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:org.pentaho.di.trans.steps.excelwriter.ExcelWriterStep.java

License:Apache License

void writeField(Object v, ValueMetaInterface vMeta, ExcelWriterStepField excelField, Row xlsRow, int posX,
        Object[] row, int fieldNr, boolean isTitle) throws KettleException {
    try {/*from   w ww  .j  ava  2s  . co m*/
        boolean cellExisted = true;
        // get the cell
        Cell cell = xlsRow.getCell(posX);
        if (cell == null) {
            cellExisted = false;
            cell = xlsRow.createCell(posX);
        }

        // if cell existed and existing cell's styles should not be changed, don't
        if (!(cellExisted && meta.isLeaveExistingStylesUnchanged())) {

            // if the style of this field is cached, reuse it
            if (!isTitle && data.getCachedStyle(fieldNr) != null) {
                cell.setCellStyle(data.getCachedStyle(fieldNr));
            } else {
                // apply style if requested
                if (excelField != null) {

                    // determine correct cell for title or data rows
                    String styleRef = null;
                    if (!isTitle && !Utils.isEmpty(excelField.getStyleCell())) {
                        styleRef = excelField.getStyleCell();
                    } else if (isTitle && !Utils.isEmpty(excelField.getTitleStyleCell())) {
                        styleRef = excelField.getTitleStyleCell();
                    }

                    if (styleRef != null) {
                        Cell styleCell = getCellFromReference(styleRef);
                        if (styleCell != null && cell != styleCell) {
                            cell.setCellStyle(styleCell.getCellStyle());
                        }
                    }
                }

                // set cell format as specified, specific format overrides cell specification
                if (!isTitle && excelField != null && !Utils.isEmpty(excelField.getFormat())
                        && !excelField.getFormat().startsWith("Image")) {
                    setDataFormat(excelField.getFormat(), cell);
                }
                // cache it for later runs
                if (!isTitle) {
                    data.cacheStyle(fieldNr, cell.getCellStyle());
                }
            }
        }

        // create link on cell if requested
        if (!isTitle && excelField != null && data.linkfieldnrs[fieldNr] >= 0) {
            String link = data.inputRowMeta.getValueMeta(data.linkfieldnrs[fieldNr])
                    .getString(row[data.linkfieldnrs[fieldNr]]);
            if (!Utils.isEmpty(link)) {
                CreationHelper ch = data.wb.getCreationHelper();
                // set the link on the cell depending on link type
                Hyperlink hyperLink = null;
                if (link.startsWith("http:") || link.startsWith("https:") || link.startsWith("ftp:")) {
                    hyperLink = ch.createHyperlink(HyperlinkType.URL);
                    hyperLink.setLabel("URL Link");
                } else if (link.startsWith("mailto:")) {
                    hyperLink = ch.createHyperlink(HyperlinkType.EMAIL);
                    hyperLink.setLabel("Email Link");
                } else if (link.startsWith("'")) {
                    hyperLink = ch.createHyperlink(HyperlinkType.DOCUMENT);
                    hyperLink.setLabel("Link within this document");
                } else {
                    hyperLink = ch.createHyperlink(HyperlinkType.FILE);
                    hyperLink.setLabel("Link to a file");
                }

                hyperLink.setAddress(link);
                cell.setHyperlink(hyperLink);

                // if cell existed and existing cell's styles should not be changed, don't
                if (!(cellExisted && meta.isLeaveExistingStylesUnchanged())) {

                    if (data.getCachedLinkStyle(fieldNr) != null) {
                        cell.setCellStyle(data.getCachedLinkStyle(fieldNr));
                    } else {
                        // CellStyle style = cell.getCellStyle();
                        Font origFont = data.wb.getFontAt(cell.getCellStyle().getFontIndex());
                        Font hlink_font = data.wb.createFont();
                        // reporduce original font characteristics

                        hlink_font.setBold(origFont.getBold());
                        hlink_font.setCharSet(origFont.getCharSet());
                        hlink_font.setFontHeight(origFont.getFontHeight());
                        hlink_font.setFontName(origFont.getFontName());
                        hlink_font.setItalic(origFont.getItalic());
                        hlink_font.setStrikeout(origFont.getStrikeout());
                        hlink_font.setTypeOffset(origFont.getTypeOffset());
                        // make it blue and underlined
                        hlink_font.setUnderline(Font.U_SINGLE);
                        hlink_font.setColor(IndexedColors.BLUE.getIndex());
                        CellStyle style = cell.getCellStyle();
                        style.setFont(hlink_font);
                        cell.setCellStyle(style);
                        data.cacheLinkStyle(fieldNr, cell.getCellStyle());
                    }
                }
            }
        }

        // create comment on cell if requrested
        if (!isTitle && excelField != null && data.commentfieldnrs[fieldNr] >= 0
                && data.wb instanceof XSSFWorkbook) {
            String comment = data.inputRowMeta.getValueMeta(data.commentfieldnrs[fieldNr])
                    .getString(row[data.commentfieldnrs[fieldNr]]);
            if (!Utils.isEmpty(comment)) {
                String author = data.commentauthorfieldnrs[fieldNr] >= 0
                        ? data.inputRowMeta.getValueMeta(data.commentauthorfieldnrs[fieldNr]).getString(
                                row[data.commentauthorfieldnrs[fieldNr]])
                        : "Kettle PDI";
                cell.setCellComment(createCellComment(author, comment));
            }
        }
        // cell is getting a formula value or static content
        if (!isTitle && excelField != null && excelField.isFormula()) {
            // formula case
            cell.setCellFormula(vMeta.getString(v));
        } else {
            // static content case
            switch (vMeta.getType()) {
            case ValueMetaInterface.TYPE_DATE:
                if (v != null && vMeta.getDate(v) != null) {
                    cell.setCellValue(vMeta.getDate(v));
                }
                break;
            case ValueMetaInterface.TYPE_BOOLEAN:
                if (v != null) {
                    cell.setCellValue(vMeta.getBoolean(v));
                }
                break;
            case ValueMetaInterface.TYPE_STRING:
            case ValueMetaInterface.TYPE_BINARY:
                if (v != null) {
                    cell.setCellValue(vMeta.getString(v));
                }
                break;
            case ValueMetaInterface.TYPE_BIGNUMBER:
            case ValueMetaInterface.TYPE_NUMBER:
            case ValueMetaInterface.TYPE_INTEGER:
                if (v != null) {
                    cell.setCellValue(vMeta.getNumber(v));
                }
                break;
            default:
                break;
            }
        }
    } catch (Exception e) {
        logError("Error writing field (" + data.posX + "," + data.posY + ") : " + e.toString());
        logError(Const.getStackTracker(e));
        throw new KettleException(e);
    }
}