org.apache.poi.ss.usermodel.Hyperlink Java Examples

The following examples show how to use org.apache.poi.ss.usermodel.Hyperlink. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LinkCellConverterTest.java    From xlsmapper with Apache License 2.0 6 votes vote down vote up
public String getFormula2(Point point, Cell cell) {

            if(Utils.equals(comment, "空文字")) {
                return null;

            }

            // ダミーでリンクも設定する
            final CreationHelper helper = cell.getSheet().getWorkbook().getCreationHelper();
            final Hyperlink link = helper.createHyperlink(HyperlinkType.URL);
            link.setAddress(comment);
            cell.setHyperlink(link);

            final int rowNumber = point.y + 1;
            return String.format("HYPERLINK(D%s,\"リンク\"&A%s)", rowNumber, rowNumber);
        }
 
Example #2
Source File: CellLinkCellConverterFactory.java    From xlsmapper with Apache License 2.0 6 votes vote down vote up
@Override
protected void setupCell(final Cell cell, final Optional<CellLink> cellValue) throws TypeBindException {
    
    // 既存のハイパーリンクを削除
    // 削除しないと、Excelの見た目上はリンクは変わっているが、データ上は2重にリンクが設定されている。
    cell.removeHyperlink();
    
    if(cellValue.isPresent()) {
        final CreationHelper helper = cell.getSheet().getWorkbook().getCreationHelper();
        final HyperlinkType type = POIUtils.judgeLinkType(cellValue.get().getLink());
        final Hyperlink link = helper.createHyperlink(type);
        link.setAddress(cellValue.get().getLink());
        cell.setHyperlink(link);
        
        cell.setCellValue(cellValue.get().getLabel());
        
    } else {
        cell.setCellType(CellType.BLANK);
    }
    
}
 
Example #3
Source File: CellLinkCellConverterFactory.java    From xlsmapper with Apache License 2.0 6 votes vote down vote up
@Override
protected CellLink parseCell(final Cell evaluatedCell, final String formattedValue) throws TypeBindException {
    
    final Optional<XlsTrim> trimAnno = getField().getAnnotation(XlsTrim.class);
    
    final Hyperlink hyperlink = POIUtils.getHyperlink(evaluatedCell);
    if(hyperlink != null) {
        // リンクが設定されているセルは、リンクの内容を値とする
        final String address = Utils.trim(hyperlink.getAddress(), trimAnno);
        final String label = Utils.trim(formattedValue, trimAnno);
        
        return new CellLink(address, label);
        
    } else if(!formattedValue.isEmpty()) {
        // リンクがないセルは、セルの文字列を値とする
        return new CellLink(null, formattedValue);
    }
    
    return null;
}
 
Example #4
Source File: URICellConverterFactory.java    From xlsmapper with Apache License 2.0 6 votes vote down vote up
@Override
protected void setupCell(final Cell cell, final Optional<URI> cellValue) throws TypeBindException {
    
    // 既存のハイパーリンクを削除
    // 削除しないと、Excelの見た目上はリンクは変わっているが、データ上は2重にリンクが設定されている。
    cell.removeHyperlink();
    
    if(cellValue.isPresent()) {
        final CreationHelper helper = cell.getSheet().getWorkbook().getCreationHelper();
        final Hyperlink link = helper.createHyperlink(HyperlinkType.URL);
        link.setAddress(cellValue.get().toString());
        cell.setHyperlink(link);
        
        cell.setCellValue(cellValue.get().toString());
        
    } else {
        cell.setCellType(CellType.BLANK);
    }
    
}
 
Example #5
Source File: JRXlsMetadataExporter.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void importValues(				
	CellType cellType,
	HSSFCellStyle cellStyle,
	Object cellValue,
	String formula,
	Hyperlink link
	) 
{
	if(!CellType.FORMULA.equals(cellType))
	{
		this.cellType = cellType;
	}
	this.cellStyle = cellStyle;
	this.cellValue = cellValue;
	this.formula = formula;
	this.link = link;
}
 
Example #6
Source File: ExcelCell.java    From objectlabkit with Apache License 2.0 5 votes vote down vote up
public ExcelCell link(String url, String label) {
    final CreationHelper creationHelper = row().sheet().workbook().poiWorkbook().getCreationHelper();
    final Hyperlink hl = creationHelper.createHyperlink(HyperlinkType.URL);
    hl.setAddress(url);
    hl.setLabel(label);
    currentCell.setCellValue(label);
    currentCell.setHyperlink(hl);
    style(LINK);
    return this;
}
 
Example #7
Source File: POIUtils.java    From xlsmapper with Apache License 2.0 5 votes vote down vote up
/**
 * ハイパーリンクを取得する。
 * <p>結合されているセルの場合にも対応。
 * @param cell
 * @return 見つからない場合は、nullを返す。
 * @throws IllegalArgumentException {@literal cell is null.}
 */
public static Hyperlink getHyperlink(final Cell cell) {

    ArgUtils.notNull(cell, "cell");

    Hyperlink link = cell.getHyperlink();
    if(link != null) {
        return link;
    }

    final Sheet sheet = cell.getSheet();
    CellRangeAddress mergedRange = getMergedRegion(sheet, cell.getRowIndex(), cell.getColumnIndex());
    if(mergedRange == null) {
        return null;
    }

    for(Hyperlink item : sheet.getHyperlinkList()) {
        if(item.getFirstRow() == mergedRange.getFirstRow()
                && item.getFirstColumn() == mergedRange.getFirstColumn()) {
            return item;
        }

    }

    return null;

}
 
Example #8
Source File: EventWorksheet.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private Hyperlink setAttachmentURLLinks(SignupAttachment attach) {
	Hyperlink hsHyperlink = wb.getCreationHelper().createHyperlink(HyperlinkType.URL);
	String link = this.sakaiFacade.getServerConfigurationService().getServerUrl()
			+ attach.getLocation();
	hsHyperlink.setAddress(link);
	hsHyperlink.setLabel(attach.getFilename());
	return hsHyperlink;
}
 
Example #9
Source File: CustomCellWriteHandler.java    From easyexcel with Apache License 2.0 5 votes vote down vote up
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
    List<CellData> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
    // 这里可以对cell进行任何操作
    LOGGER.info("第{}行,第{}列写入完成。", cell.getRowIndex(), cell.getColumnIndex());
    if (isHead && cell.getColumnIndex() == 0) {
        CreationHelper createHelper = writeSheetHolder.getSheet().getWorkbook().getCreationHelper();
        Hyperlink hyperlink = createHelper.createHyperlink(HyperlinkType.URL);
        hyperlink.setAddress("https://github.com/alibaba/easyexcel");
        cell.setHyperlink(hyperlink);
    }
}
 
Example #10
Source File: EventWorksheet.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private Hyperlink setAttachmentURLLinks(SignupAttachment attach) {
	Hyperlink hsHyperlink = wb.getCreationHelper().createHyperlink(HyperlinkType.URL);
	String link = this.sakaiFacade.getServerConfigurationService().getServerUrl()
			+ attach.getLocation();
	hsHyperlink.setAddress(link);
	hsHyperlink.setLabel(attach.getFilename());
	return hsHyperlink;
}
 
Example #11
Source File: JRXlsMetadataExporter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
public CellSettings(
	CellType cellType,
	HSSFCellStyle cellStyle,
	Object cellValue,
	String formula,
	Hyperlink link
	) 
{
	this.cellType = cellType;
	this.cellStyle = cellStyle;
	this.cellValue = cellValue;
	this.formula = formula;
	this.link = link;
}
 
Example #12
Source File: AbstractExcelFactory.java    From myexcel with Apache License 2.0 5 votes vote down vote up
private Cell setLink(Td td, Row currentRow, HyperlinkType hyperlinkType) {
    if (StringUtil.isBlank(td.getContent())) {
        return currentRow.createCell(td.getCol());
    }
    if (createHelper == null) {
        createHelper = workbook.getCreationHelper();
    }
    Cell cell = currentRow.createCell(td.getCol(), CellType.STRING);
    cell.setCellValue(td.getContent());
    Hyperlink link = createHelper.createHyperlink(hyperlinkType);
    link.setAddress(td.getLink());
    cell.setHyperlink(link);
    return cell;
}
 
Example #13
Source File: HSSFCell.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Assign a hyperlink to this cell. If the supplied hyperlink is null, the
 * hyperlink for this cell will be removed.
 *
 * @param hyperlink hyperlink associated with this cell
 */
@Override
public void setHyperlink(Hyperlink hyperlink){
    if (hyperlink == null) {
        removeHyperlink();
        return;
    }

    HSSFHyperlink link = (HSSFHyperlink)hyperlink;

    link.setFirstRow(_record.getRow());
    link.setLastRow(_record.getRow());
    link.setFirstColumn(_record.getColumn());
    link.setLastColumn(_record.getColumn());

    switch(link.getTypeEnum()){
        case EMAIL:
        case URL:
            link.setLabel("url");
            break;
        case FILE:
            link.setLabel("file");
            break;
        case DOCUMENT:
            link.setLabel("place");
            break;
        default:
            break;
    }

    List<RecordBase> records = _sheet.getSheet().getRecords();
    int eofLoc = records.size() - 1;
    records.add( eofLoc, link.record );
}
 
Example #14
Source File: HSSFHyperlink.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected HSSFHyperlink(Hyperlink other) {
    if (other instanceof HSSFHyperlink) {
        HSSFHyperlink hlink = (HSSFHyperlink) other;
        record = hlink.record.clone();
        link_type = getType(record);
    }
    else {
        link_type = other.getTypeEnum();
        record = new HyperlinkRecord();
        setFirstRow(other.getFirstRow());
        setFirstColumn(other.getFirstColumn());
        setLastRow(other.getLastRow());
        setLastColumn(other.getLastColumn());
    }
}
 
Example #15
Source File: StreamingSheet.java    From data-prep with Apache License 2.0 4 votes vote down vote up
@Override
public Hyperlink getHyperlink(int row, int column) {
    throw new UnsupportedOperationException();
}
 
Example #16
Source File: StreamingSheet.java    From data-prep with Apache License 2.0 4 votes vote down vote up
@Override
public List<? extends Hyperlink> getHyperlinkList() {
    throw new UnsupportedOperationException();
}
 
Example #17
Source File: StreamingSheet.java    From data-prep with Apache License 2.0 4 votes vote down vote up
@Override
public Hyperlink getHyperlink(CellAddress addr) {
    throw new UnsupportedOperationException();
}
 
Example #18
Source File: JRXlsMetadataExporter.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setLink(Hyperlink link) {
	this.link = link;
}
 
Example #19
Source File: StreamingSheet.java    From excel-streaming-reader with Apache License 2.0 4 votes vote down vote up
/**
 * Not supported
 */
@Override
public Hyperlink getHyperlink(int i, int i1) {
  throw new UnsupportedOperationException();
}
 
Example #20
Source File: StreamingSheet.java    From excel-streaming-reader with Apache License 2.0 4 votes vote down vote up
/**
 * Not supported
 */
@Override
public Hyperlink getHyperlink(CellAddress cellAddress) {
  throw new UnsupportedOperationException();
}
 
Example #21
Source File: StreamingSheet.java    From excel-streaming-reader with Apache License 2.0 4 votes vote down vote up
/**
 * Not supported
 */
@Override
public List<? extends Hyperlink> getHyperlinkList() {
  throw new UnsupportedOperationException();
}
 
Example #22
Source File: StreamingCell.java    From excel-streaming-reader with Apache License 2.0 4 votes vote down vote up
/**
 * Not supported
 */
@Override
public Hyperlink getHyperlink() {
  throw new NotSupportedException();
}
 
Example #23
Source File: StreamingCell.java    From excel-streaming-reader with Apache License 2.0 4 votes vote down vote up
/**
 * Not supported
 */
@Override
public void setHyperlink(Hyperlink link) {
  throw new NotSupportedException();
}
 
Example #24
Source File: JRXlsMetadataExporter.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Hyperlink getLink() {
	return link;
}