Search in sources :

Example 1 with XSSFHyperlink

use of org.apache.poi.xssf.usermodel.XSSFHyperlink in project poi by apache.

the class XSSFRowShifter method updateHyperlinks.

/**
     * Shift the Hyperlink anchors (not the hyperlink text, even if the hyperlink
     * is of type LINK_DOCUMENT and refers to a cell that was shifted). Hyperlinks
     * do not track the content they point to.
     *
     * @param shifter
     */
public void updateHyperlinks(FormulaShifter shifter) {
    int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet);
    List<? extends Hyperlink> hyperlinkList = sheet.getHyperlinkList();
    for (Hyperlink hyperlink : hyperlinkList) {
        XSSFHyperlink xhyperlink = (XSSFHyperlink) hyperlink;
        String cellRef = xhyperlink.getCellRef();
        CellRangeAddress cra = CellRangeAddress.valueOf(cellRef);
        CellRangeAddress shiftedRange = shiftRange(shifter, cra, sheetIndex);
        if (shiftedRange != null && shiftedRange != cra) {
            // shiftedRange should not be null. If shiftedRange is null, that means
            // that a hyperlink wasn't deleted at the beginning of shiftRows when
            // identifying rows that should be removed because they will be overwritten
            xhyperlink.setCellReference(shiftedRange.formatAsString());
        }
    }
}
Also used : CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) XSSFHyperlink(org.apache.poi.xssf.usermodel.XSSFHyperlink) Hyperlink(org.apache.poi.ss.usermodel.Hyperlink) XSSFHyperlink(org.apache.poi.xssf.usermodel.XSSFHyperlink)

Example 2 with XSSFHyperlink

use of org.apache.poi.xssf.usermodel.XSSFHyperlink in project dhis2-core by dhis2.

the class ExcelNodeSerializer method startWriteRootNode.

@Override
protected void startWriteRootNode(RootNode rootNode) throws Exception {
    XSSFCreationHelper creationHelper = workbook.getCreationHelper();
    int rowIdx = 1;
    for (Node collectionNode : rootNode.getChildren()) {
        if (collectionNode.isCollection()) {
            for (Node complexNode : collectionNode.getChildren()) {
                XSSFRow row = sheet.createRow(rowIdx++);
                int cellIdx = 0;
                for (Node node : complexNode.getChildren()) {
                    if (node.isSimple()) {
                        XSSFCell cell = row.createCell(cellIdx++);
                        cell.setCellValue(getValue((SimpleNode) node));
                        if (node.haveProperty() && PropertyType.URL.equals(node.getProperty().getPropertyType())) {
                            XSSFHyperlink hyperlink = creationHelper.createHyperlink(HyperlinkType.URL);
                            hyperlink.setAddress(getValue((SimpleNode) node));
                            hyperlink.setLabel(getValue((SimpleNode) node));
                            cell.setHyperlink(hyperlink);
                        } else if (node.haveProperty() && PropertyType.EMAIL.equals(node.getProperty().getPropertyType())) {
                            XSSFHyperlink hyperlink = creationHelper.createHyperlink(HyperlinkType.EMAIL);
                            hyperlink.setAddress(getValue((SimpleNode) node));
                            hyperlink.setLabel(getValue((SimpleNode) node));
                            cell.setHyperlink(hyperlink);
                        }
                    }
                }
            }
        }
    }
}
Also used : XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFCreationHelper(org.apache.poi.xssf.usermodel.XSSFCreationHelper) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Node(org.hisp.dhis.node.Node) SimpleNode(org.hisp.dhis.node.types.SimpleNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) RootNode(org.hisp.dhis.node.types.RootNode) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell) SimpleNode(org.hisp.dhis.node.types.SimpleNode) XSSFHyperlink(org.apache.poi.xssf.usermodel.XSSFHyperlink)

Example 3 with XSSFHyperlink

use of org.apache.poi.xssf.usermodel.XSSFHyperlink in project poi by apache.

the class SXSSFCell method setHyperlink.

/**
     * Assign a hyperlink to this cell. If the supplied hyperlink is null, the
     * hyperlink for this cell will be removed.
     *
     * @param link hyperlink associated with this cell
     */
@Override
public void setHyperlink(Hyperlink link) {
    if (link == null) {
        removeHyperlink();
        return;
    }
    setProperty(Property.HYPERLINK, link);
    XSSFHyperlink xssfobj = (XSSFHyperlink) link;
    // Assign to us
    CellReference ref = new CellReference(getRowIndex(), getColumnIndex());
    xssfobj.setCellReference(ref);
    // Add to the lists
    getSheet()._sh.addHyperlink(xssfobj);
}
Also used : CellReference(org.apache.poi.ss.util.CellReference) XSSFHyperlink(org.apache.poi.xssf.usermodel.XSSFHyperlink)

Aggregations

XSSFHyperlink (org.apache.poi.xssf.usermodel.XSSFHyperlink)3 Hyperlink (org.apache.poi.ss.usermodel.Hyperlink)1 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)1 CellReference (org.apache.poi.ss.util.CellReference)1 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)1 XSSFCreationHelper (org.apache.poi.xssf.usermodel.XSSFCreationHelper)1 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)1 Node (org.hisp.dhis.node.Node)1 CollectionNode (org.hisp.dhis.node.types.CollectionNode)1 ComplexNode (org.hisp.dhis.node.types.ComplexNode)1 RootNode (org.hisp.dhis.node.types.RootNode)1 SimpleNode (org.hisp.dhis.node.types.SimpleNode)1