Hi,
I need to get all hyperlinks from an excel file. Therefore I wrote a little
method using POI. I take the getType() method to get the type of the hyperlink,
but all I got is the return value 0. For example for an email address I
expected the value of HSSFHyperlink.LINK_EMAIL but I got 0. Is this a bug or is
anything wrong with my code?
- greets Bastian
CODE
public static void testExcel() throws FileNotFoundException, IOException {
final HSSFWorkbook workbook = new HSSFWorkbook(new
FileInputStream("C:\\test.xls"));
for (int iSheet = 0; iSheet < workbook.getNumberOfSheets(); iSheet++) {
final HSSFSheet sheet = workbook.getSheetAt(iSheet);
for (final Iterator<Row> iterRows = sheet.rowIterator();
iterRows.hasNext();) {
final HSSFRow row = (HSSFRow) iterRows.next();
for (final Iterator<Cell> iterCells = row.cellIterator();
iterCells.hasNext();) {
final HSSFCell cell = (HSSFCell) iterCells.next();
final HSSFHyperlink hyperlink = cell.getHyperlink();
if (hyperlink != null) {
System.out.println("hyperlink: [" + hyperlink.getLabel() + "]");
System.out.println(" address: [" + hyperlink.getAddress() +
"]");
System.out.println(" type: [" + hyperlink.getType() + "]");
switch (hyperlink.getType()) {
case HSSFHyperlink.LINK_DOCUMENT:
System.out.println("document");
break;
case HSSFHyperlink.LINK_EMAIL:
System.out.println("email");
break;
case HSSFHyperlink.LINK_FILE:
System.out.println("file");
break;
case HSSFHyperlink.LINK_URL:
System.out.println("url");
break;
default:
System.out.println("can't determine linktype");
break;
}
}
}
}
}
}
OUTPUT
hyperlink: [null]
address: [http://www.google.de]
type: [0]
can't determine linktype
hyperlink: [null]
address: [test.doc]
type: [0]
can't determine linktype
hyperlink: [null]
address: [D:\test\test.jpg]
type: [0]
can't determine linktype
hyperlink: [test]
address: [D:\test\test.pdf]
type: [0]
can't determine linktype
hyperlink: [null]
address: [Arbeitsplatz]
type: [0]
can't determine linktype
hyperlink: [[email protected]]
address: [mailto:[email protected]]
type: [0]
can't determine linktype
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]