You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Bastian Schurr <Ba...@gmx.de> on 2010/01/05 13:07:45 UTC
return of method getType() from HSSFHyperlink
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: [test@web.de]
address: [mailto:test@web.de]
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: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: return of method getType() from HSSFHyperlink
Posted by Nick Burch <ni...@alfresco.com>.
Bastian Schurr wrote:
> 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.
It seems that HSSFHyperLink wasn't pulling through the type from the
underlying record. Now fixed in svn.
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org