• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading hyperlink in excel through Java

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See java.net.URL.getContent(). What it returns is implementation-specific, but most likely an InputStream.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
URL.openStream() will definitely return an InputStream.
 
purnima Nair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic