• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Reading hyperlink in excel through Java

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See java.net.URL.getContent(). What it returns is implementation-specific, but most likely an InputStream.
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
URL.openStream() will definitely return an InputStream.
 
purnima Nair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Marshal
Posts: 69813
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. Your code is too difficult to read without code tags.
 
purnima Nair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is as below:


Am getting java.net.UnknownHostException: www.google.com
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may need a proxy for connecting. Use this code for setting the proxy

Hope it helps.
 
purnima Nair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic