org.apache.poi.ss.usermodel.Hyperlink类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(293)

本文整理了Java中org.apache.poi.ss.usermodel.Hyperlink类的一些代码示例,展示了Hyperlink类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hyperlink类的具体详情如下:
包路径:org.apache.poi.ss.usermodel.Hyperlink
类名称:Hyperlink

Hyperlink介绍

[英]Represents an Excel hyperlink.
[中]表示Excel超链接。

代码示例

代码示例来源:origin: apache/tika

@Override
  public void applyStyleAndValue(int dbColNum, ResultSet resultSet, Cell cell) throws SQLException {
    if (links < MAX_HYPERLINKS) {
      Hyperlink hyperlink = workbook.getCreationHelper().createHyperlink(linkType);
      String path = resultSet.getString(dbColNum);
      String address = urlBase+path;
      hyperlink.setAddress(address);
      cell.setHyperlink(hyperlink);
      cell.setCellStyle(style);
      String fName = Paths.get(path).getFileName().toString();
      cell.setCellValue(fName);
      links++;
    } else {
      //silently stop adding hyperlinks
    }
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * 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()));
  }
}
/**

代码示例来源:origin: pentaho/pentaho-kettle

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 );

代码示例来源:origin: org.apache.poi/poi

protected HSSFHyperlink(Hyperlink other) {
  if (other instanceof HSSFHyperlink) {
    HSSFHyperlink hlink = (HSSFHyperlink) other;
    record = hlink.record.clone();
    link_type = getType(record);
  }
  else {
    link_type = other.getType();
    record = new HyperlinkRecord();
    setFirstRow(other.getFirstRow());
    setFirstColumn(other.getFirstColumn());
    setLastRow(other.getLastRow());
    setLastColumn(other.getLastColumn());
  }
}

代码示例来源:origin: tobyweston/simple-excel

private boolean containsUrl(org.apache.poi.ss.usermodel.Hyperlink hyperlink) {
    return hyperlink.getAddress().startsWith("http://") || hyperlink.getAddress().startsWith("file://");
  }
},

代码示例来源:origin: stackoverflow.com

Workbook wb = WorkbookFactory.create(new File("test.xls"));
Sheet s = wb.getSheetAt(0);
Row r2 = s.getRow(1); // Rows in POI are 0 based
Cell cB2 = r2.getCell(1); // Cells are 0 based

Hyperlink h = cB2.getHyperlink();
if (h == null) {
  System.err.println("Cell B2 didn't have a hyperlink!");
} else {
  System.out.println("B2 : " + h.getLabel() + " -> " + h.getAddress());
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

protected HSSFHyperlink(Hyperlink other) {
  if (other instanceof HSSFHyperlink) {
    HSSFHyperlink hlink = (HSSFHyperlink) other;
    record = hlink.record.clone();
    link_type = getType(record);
  }
  else {
    link_type = other.getType();
    record = new HyperlinkRecord();
    setFirstRow(other.getFirstRow());
    setFirstColumn(other.getFirstColumn());
    setLastRow(other.getLastRow());
    setLastColumn(other.getLastColumn());
  }
}

代码示例来源:origin: stackoverflow.com

Workbook wb = WorkbookFactory.create(new File(FilePath));
Sheet TestSheet = wb.getSheetAt(0);
Cell cell = TestSheet.getRow(0).getCell(0);
Hyperlink linkAddress = cell.getHyperlink();
if(linkAddress != null){
  System.out.println(linkAddress .getAddress());
}

代码示例来源:origin: stackoverflow.com

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);

代码示例来源:origin: stackoverflow.com

Hyperlink hyperlink = creationHelper.createHyperlink(Hyperlink.LINK_FILE);
String relativePath = "../parentdir/fileToLink.txt";
hyperlink.setAddress(relativePath);
hyperlink.setLabel("Link to file");
cell.setHyperlink(hyperlink);
cell.setCellValue("Link to file");
cell.setCellType(Cell.CELL_TYPE_STRING);

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * 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()));
  }
}
/**

代码示例来源:origin: stackoverflow.com

ex[2] = h.getAddress();

代码示例来源:origin: stackoverflow.com

if(row.get(j) instanceof Link){
  Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
  link.setAddress("http://poi.apache.org/");
  cell.setHyperlink(link);
}else{
  Your code..
}

代码示例来源:origin: Appendium/objectlabkit

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;
}

代码示例来源:origin: com.itelg/texin

if (cell.getHyperlink() != null)
  return cell.getHyperlink().getAddress();

代码示例来源:origin: stackoverflow.com

Elements tds = row.select("td");
count = 0; //cell location at that row
for (Element element : tds) {
  cell = header.createCell(count);            

  cell.setCellValue(element.text());
  Element href = element.select("a[href]").first();
  if (href != null){
     Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
     link.setAddress(href.attr("href"));
     cell.setHyperlink(link); 
  }
  count++;
}

代码示例来源:origin: com.b2international.snowowl/com.b2international.snowowl.datastore.server

/**
 * Creates the index sheet based on the given sheet names.
 * 
 * @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);
}

代码示例来源:origin: tobyweston/simple-excel

@Override
public Cell adapt(org.apache.poi.ss.usermodel.Cell cell) {
  if (cell.getHyperlink() != null && containsUrl(cell.getHyperlink()))
    return new HyperlinkCell(hyperlink(cell.getStringCellValue(), cell.getHyperlink().getAddress()));
  
  if (cell.getStringCellValue() == null || "".equals(cell.getStringCellValue()))
    return new BlankCell();
  
  return new StringCell(cell.getStringCellValue());
}

代码示例来源:origin: stackoverflow.com

CreationHelper creationHelper = getWorkbook().getCreationHelper();
Hyperlink link = creationHelper.createHyperlink(Hyperlink.LINK_URL);
link.setAddress("www.google.com");

代码示例来源:origin: hellojavaer/poi-excel-utils

Hyperlink hyperlink = cell.getHyperlink();
if (hyperlink != null) {
  address = hyperlink.getAddress();

相关文章