java - 获取Excel文件中单元格的超链接

标签 java excel apache-poi

我正在尝试使用此方法获取 Excel 文件中单元格的超链接和标签
库(该库基于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) at com.z2data.mapping.ExeclHorizental.getCurrentRow(ExeclHorizental.java:88)

最佳答案

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

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

关于java - 获取Excel文件中单元格的超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42629524/

相关文章:

Java、HTTP 和套接字 : When to stop reading the request but keep the socket open?

excel - 无法通过 getOpenFilename 打开 excel 文件

Java实现多线程(excel处理)

java - 是否可以在 linux 上安装 64 位 JVM,以便堆可以大于 2gb?

java - Libgdx 存储游戏元素

java - 在二叉树中查找节点深度而不是 BST

excel - 计算列中的连续数字

vba - 在 Excel 中比较和计算连续数据

java - 线程 "main"java.lang.NoSuchFieldError : Factory question 中出现异常

java - 如何计算从一个方法发送到另一个方法的参数总数