在Excel文件中获取Cell的超链接

时间:2017-03-06 15:32:09

标签: java excel apache-poi

我正试图使用​​这个来获取Excel文件中单元格的超链接和标签 library(这个库基于apache POI)

https://github.com/monitorjbl/excel-streaming-reader#supported-methods

我试过这个

 InputStream is = new FileInputStream("file");
 Workbook   workbook = StreamingReader.builder().rowCacheSize(100)   
                        .bufferSize(4096)   
                        .open(is);   
 Iterator<Row>    rowIterator=workbook.getSheetAt(0).iterator();
 Row row=rowIterator.next();
 Iterator<Cell> cellIterator = row.cellIterator();
 Cell currentCell = cellIterator.next();
 String parthyperlink=currentCell.getHyperlink().getAddress();
 String label=currentCell.getHyperlink().getLabel();

但是我得到了这个例外

  

com.monitorjbl.xlsx.exceptions.NotSupportedException at   com.monitorjbl.xlsx.impl.StreamingCell.getHyperlink(StreamingCell.java:353)   在   com.z2data.mapping.ExeclHorizental.getCurrentRow(ExeclHorizental.java:88)

1 个答案:

答案 0 :(得分:1)

超链接不是字符串。实际上是实例化超链接。试试这个:

Hyperlink h = currentCell.getHyperlink();

然后,您可以获取特定单元格的地址

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