2017-03-06 153 views
1

我正在嘗試使用這個
庫,以獲得在Excel文件中的單元格的超鏈接和標籤(該庫是基於Apache POI)在Excel中獲取細胞的超鏈接文件

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在 com.monitorjbl.xlsx.impl.StreamingCell.getHyperlink(StreamingCell.java:353) 在 com.z2data.mapping.ExeclHorizental.getCurrentRow(ExeclHorizental.java:88)

+0

https://github.com/monitorjbl/excel-streaming-reader/blob/master/src/main/地址java/com/monitorjbl/xlsx/impl/StreamingCell.java#L432 –

+0

爲什麼不使用普通的Apache POI? – Gagravarr

+0

@Gagravarr因爲我有大文件,並根據這個答案http://stackoverflow.com/questions/11891851/how-to-load-a-large-xlsx-file-with-apache-poi我選擇excel-streaming-讀者 – Elsayed

回答

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

我試過這個,但它給了我同樣的例外。 – Elsayed

+0

單元格是否爲空?你有嘗試把它放在try/catch塊嗎? – Jay266

+0

是的,我把它放在try/catch塊中 – Elsayed