I 'am trying to get hyperlink and label of a cell in Excel file using this
library (this library is based on apache POI)
我正在尝试使用这个库在Excel文件中获取一个单元格的超链接和标签(这个库基于apache POI)
https://github.com/monitorjbl/excel-streaming-reader#supported-methods
https://github.com/monitorjbl/excel-streaming-reader支持方法
I tried this
我试着这
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();
but I get this Exception
但我有这个例外
com.monitorjbl.xlsx.exceptions.NotSupportedException at com.monitorjbl.xlsx.impl.StreamingCell.getHyperlink(StreamingCell.java:353) at com.z2data.mapping.ExeclHorizental.getCurrentRow(ExeclHorizental.java:88)
com.monitorjbl.xlsx.exceptions。com. monitorjlsx .impl. streamingcell.gethyperlink (StreamingCell.java:353) at com.z2data.mapp . execlhorizonent.getcurrentrow .java:88)
1 个解决方案
#1
1
Hyperlink is not a a string. Instantiate a Hyperlink instead. Try this:
超链接不是字符串。实例化一个超链接。试试这个:
Hyperlink h = currentCell.getHyperlink();
You can then fetch the address of the particular cell
然后可以获取特定单元格的地址
if (h == null) {
System.err.println("Cell didn't have a hyperlink!");
} else {
System.out.println("Cell : " + h.getLabel() + " -> " + h.getAddress());
}
#1
1
Hyperlink is not a a string. Instantiate a Hyperlink instead. Try this:
超链接不是字符串。实例化一个超链接。试试这个:
Hyperlink h = currentCell.getHyperlink();
You can then fetch the address of the particular cell
然后可以获取特定单元格的地址
if (h == null) {
System.err.println("Cell didn't have a hyperlink!");
} else {
System.out.println("Cell : " + h.getLabel() + " -> " + h.getAddress());
}