@Internal public void setCellReference(CellReference ref) { setCellReference(ref.formatAsString()); }
/** * Create a new XSSFHyperlink. * * @param type - the type of hyperlink to create, see {@link Hyperlink} */ @Override public XSSFHyperlink createHyperlink(HyperlinkType type) { return new XSSFHyperlink(type); }
/** * Return the column of the last cell that contains the hyperlink * * @return the 0-based column of the last cell that contains the hyperlink */ @Override public int getLastColumn() { return buildCellReference().getCol(); }
/** * Set the column of the first cell that contains the hyperlink * * @param col the 0-based column of the first cell that contains the hyperlink */ @Override public void setFirstColumn(int col) { setCellReference(new CellReference( getFirstRow(), col )); }
/** * Set the row of the first cell that contains the hyperlink * * @param row the 0-based row of the first cell that contains the hyperlink */ @Override public void setFirstRow(int row) { setCellReference(new CellReference( row, getFirstColumn() )); }
/*package*/ static void updateHyperlinks(Sheet sheet, FormulaShifter formulaShifter) { 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 = BaseRowColShifter.shiftRange(formulaShifter, 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()); } } }
hyperlink.generateRelationIfNeeded(getPackagePart()); ctHls[i] = hyperlink.getCTHyperlink();
/** * Create a new XSSFHyperlink. This method is for Internal use only. * XSSFHyperlinks can be created by {@link XSSFCreationHelper}. * See the <a href="https://poi.apache.org/spreadsheet/quick-guide.html#Hyperlinks">spreadsheet quick-guide</a> * for an example. * * @param other the hyperlink to copy */ @Internal //FIXME: change to protected if/when SXSSFHyperlink class is created public XSSFHyperlink(Hyperlink other) { if (other instanceof XSSFHyperlink) { XSSFHyperlink xlink = (XSSFHyperlink) other; _type = xlink.getType(); _location = xlink._location; _externalRel = xlink._externalRel; _ctHyperlink = (CTHyperlink) xlink._ctHyperlink.copy(); } else { _type = other.getType(); _location = other.getAddress(); _externalRel = null; _ctHyperlink = CTHyperlink.Factory.newInstance(); setCellReference(new CellReference(other.getFirstRow(), other.getFirstColumn())); } } /**
hyperlink.setAddress( getValue( (SimpleNode) node ) ); hyperlink.setLabel( getValue( (SimpleNode) node ) ); hyperlink.setAddress( getValue( (SimpleNode) node ) ); hyperlink.setLabel( getValue( (SimpleNode) node ) );
/** * Get a Hyperlink in this sheet located in a cell specified by {code addr} * * @param addr The address of the cell containing the hyperlink * @return hyperlink if there is a hyperlink anchored at {@code addr}; otherwise returns {@code null} * @since POI 3.15 beta 3 */ @Override public XSSFHyperlink getHyperlink(CellAddress addr) { String ref = addr.formatAsString(); for(XSSFHyperlink hyperlink : hyperlinks) { if(hyperlink.getCellRef().equals(ref)) { return hyperlink; } } return null; }
private void createCellHyperLink(Cell cell, EntityInfo eInfo, Object val, XSSFWorkbook workbook) { CellStyle style = workbook.createCellStyle(); Font font = workbook.createFont(); font.setUnderline(Font.U_SINGLE); font.setColor(HSSFColor.BLUE.index); style.setFont(font); XSSFHyperlink hLink = null; if(EMAIL.equals(eInfo.getSemantics())){ hLink = workbook.getCreationHelper().createHyperlink(HyperlinkType.EMAIL); hLink.setAddress("mailto:"+String.valueOf(val)); }else if(URL.equals(eInfo.getSemantics())){ hLink = workbook.getCreationHelper().createHyperlink(HyperlinkType.URL); hLink.setAddress(String.valueOf(val)); } if(hLink != null){ cell.setHyperlink(hLink); cell.setCellStyle(style); } }
/** * Generates the relation if required */ protected void generateRelationIfNeeded(PackagePart sheetPart) { if (_externalRel == null && needsRelationToo()) { // Generate the relation PackageRelationship rel = sheetPart.addExternalRelationship(_location, XSSFRelation.SHEET_HYPERLINKS.getRelation()); // Update the r:id _ctHyperlink.setId(rel.getId()); } }
/** * Set the row of the first cell that contains the hyperlink * * @param row the 0-based row of the first cell that contains the hyperlink */ public void setFirstRow(int row) { _ctHyperlink.setRef( new CellReference( row, getFirstColumn() ).formatAsString() ); }
/** * Set the column of the first cell that contains the hyperlink * * @param col the 0-based column of the first cell that contains the hyperlink */ public void setFirstColumn(int col) { _ctHyperlink.setRef( new CellReference( getFirstRow(), col ).formatAsString() ); }
/** * Assign a hyperlink to this cell * * @param link hyperlink associated with this cell */ public void setHyperlink(Hyperlink link) { setProperty(Property.HYPERLINK,link); XSSFHyperlink xssfobj = (XSSFHyperlink)link; // Assign to us CellReference ref = new CellReference(getRowIndex(), getColumnIndex()); xssfobj.getCTHyperlink().setRef( ref.formatAsString() ); // Add to the lists ((SXSSFSheet)getSheet())._sh.addHyperlink(xssfobj); }
hyperlink.generateRelationIfNeeded(getPackagePart()); ctHls[i] = hyperlink.getCTHyperlink();
/** * Set the column of the first cell that contains the hyperlink * * @param col the 0-based column of the first cell that contains the hyperlink */ @Override public void setFirstColumn(int col) { setCellReference(new CellReference( getFirstRow(), col )); }
/** * Set the row of the first cell that contains the hyperlink * * @param row the 0-based row of the first cell that contains the hyperlink */ @Override public void setFirstRow(int row) { setCellReference(new CellReference( row, getFirstColumn() )); }
/*package*/ static void updateHyperlinks(Sheet sheet, FormulaShifter formulaShifter) { 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 = BaseRowColShifter.shiftRange(formulaShifter, 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()); } } }
/** * Create a new XSSFHyperlink. This method is for Internal use only. * XSSFHyperlinks can be created by {@link XSSFCreationHelper}. * See the <a href="https://poi.apache.org/spreadsheet/quick-guide.html#Hyperlinks">spreadsheet quick-guide</a> * for an example. * * @param other the hyperlink to copy */ @Internal //FIXME: change to protected if/when SXSSFHyperlink class is created public XSSFHyperlink(Hyperlink other) { if (other instanceof XSSFHyperlink) { XSSFHyperlink xlink = (XSSFHyperlink) other; _type = xlink.getType(); _location = xlink._location; _externalRel = xlink._externalRel; _ctHyperlink = (CTHyperlink) xlink._ctHyperlink.copy(); } else { _type = other.getType(); _location = other.getAddress(); _externalRel = null; _ctHyperlink = CTHyperlink.Factory.newInstance(); setCellReference(new CellReference(other.getFirstRow(), other.getFirstColumn())); } } /**