File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Web Page to Excel Sheet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Web Page to Excel Sheet" Watch "Web Page to Excel Sheet" New topic
Author

Web Page to Excel Sheet

Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 199
Hi all,
I have to read data from a web page and copy it to an Excel sheet 3 times in a day and that all should be done automatically at specified time daily.
On the part of writing data to sheet I am using Apache POI and for automating the process at specific time I am using Timer class and it's methods.
I have gone through documentation for Timer class and used some versions of schedule() method defined there but on initial testing with println method I was not able to get satisfactory results.also I am not getting how to automate the task many times in a single day at specified timings.
I am pasting initial testing code here.

URLReader.java


MyTimer.java


also suggest if there can be a better way in comparison of Timer and TimerTask using which I can interact with POI . I have heard about "Quartz",also Windows scheduling service or cronjobs should not be used acc. to my requirement.


Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42952
    
  73
If you want to schedule something 3 times a day, then the interval should be 8 hours (assuming an even spacing). What interval do you think "1000*365*24*7*60*60" represents? The presence of both "7" and "365" by itself should make you suspicious.
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 199
According to schedule() method defined in Timer class, "1000*365*24*7*60*60" is total timespan for which task should be run(As explaind by link and what I have got).



schedule(TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay.


Link

There are fair chances that I would have made a mistake in choosing the right version of schedule method because definitions given in link seem to be little bit confusing.

Also I want that business logic should be performed on fixed delay of 3 hours during my office hours starting at 10:15 AM 3 times in a day.



Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19845
    
  20

Ulf Dittmer wrote:What interval do you think "1000*365*24*7*60*60" represents? The presence of both "7" and "365" by itself should make you suspicious.

Another warning: that value is mathematically larger than Integer.MAX_VALUE so it will overflow. The result is probably even negative. The values should be turned into longs, or at least the first one: 1000L*365*24*7*60*60. Because the first one is a long the entire result will be a long and the value will not overflow.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42952
    
  73
According to schedule() method defined in Timer class, "1000*365*24*7*60*60" is total timespan for which task should be run

No. It's the period between Task invocations. (Repeated Tasks run forever, or until the web app is terminated, whichever comes first.)

Also I want that business logic should be performed on fixed delay of 3 hours during my office hours starting at 10:15 AM 3 times in a day.

One approach would be to schedule a Task to run at, say, 10 AM each day which then creates 3 worker Tasks to run in 0:15h, 3:15h and 6:15h for non-repeating execution. Another approach would be to schedule 3 worker Tasks that run at 10:15, 13:15 and 16:15 each day repeatedly.
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 199
Finally I was able to write business logic.Here is the code snippet given below.
But I am facing a new problem now.



Here I have hardcoded the value of k i.e. row no. but I am not getting how to move the cursor to new line of Excel sheet at each run of program means data should be inserted in a new row on each run of program such that value of k should be increased to one more on each run of program.


>
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 199
Anybody noticed this post?
Aby Kuriakose
Greenhorn

Joined: Apr 04, 2011
Posts: 1
Write a condition for checking the empty row before the for loop begins and assign the row value to intialize "k" in for loop.
 
Don't get me started about those stupid light bulbs.
 
subject: Web Page to Excel Sheet