aspose file tools*
The moose likes Java in General and the fly likes Reading hyperlink in excel through Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Reading hyperlink in excel through Java" Watch "Reading hyperlink in excel through Java" New topic
Author

Reading hyperlink in excel through Java

purnima Nair
Greenhorn

Joined: Oct 23, 2008
Posts: 8
Hi all,

I am using JExcel API to read excel in java.
Now the excel contains a column with hyperlinks.I need to read the contents(html file) of that hyperlink and put into another text file.

Is there any way in java where we can read the hyperlink content without actually clicking the link in the excel.

Please help.
Thanks,
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42620
    
  65
See java.net.URL.getContent(). What it returns is implementation-specific, but most likely an InputStream.


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

URL.openStream() will definitely return an InputStream.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
purnima Nair
Greenhorn

Joined: Oct 23, 2008
Posts: 8
Thanks for the reply...
I used the following code to get the contents of the link
URL url = new URL("http://www.google.com");
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
uc.setRequestProperty("User-Agent", "");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
System.out.println(str);
}
in.close();
But,it is giving error java.net.UnknownHostException: www.google.com
I am working on the LAN.If i exceute the same code outside LAN its working..What could be wrong?

Thanks,
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
Don't know. Your code is too difficult to read without code tags.
purnima Nair
Greenhorn

Joined: Oct 23, 2008
Posts: 8
The code is as below:


Am getting java.net.UnknownHostException: www.google.com
Sandeep Sanaboyina
Ranch Hand

Joined: Dec 14, 2009
Posts: 72
You may need a proxy for connecting. Use this code for setting the proxy

Hope it helps.


They say you have to be the first, the best or different. I say, is it too much to ask for all three.
purnima Nair
Greenhorn

Joined: Oct 23, 2008
Posts: 8
Its not working even by setting the proxy by using

I am able to connect to www.google.com without the proxyHost from the LAN.But when I connect using


Its gives unknownHostException in the above line.
Sandeep Sanaboyina
Ranch Hand

Joined: Dec 14, 2009
Posts: 72
Well, The following code worked for me.And when I commented out the 2 System.setProperty lines, I got an java.net.UnknownHostException: www.google.com
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

purnima Nair wrote:Its not working even by setting the proxy by using

you did replace these values with your company's proxy settings, right?

I am able to connect to www.google.com without the proxyHost from the LAN.

Do you mean from your browser? Are you sure that there is no proxy filled in for you?

If you open a command window and type in "ping www.google.com", can it resolve the host name?
 
Don't get me started about those stupid light bulbs.
 
subject: Reading hyperlink in excel through Java