Author |
Message |
rto
|
Posted: Tue Jun 10, 2008 7:56 am Post subject: opening excel |
|
|
Alright guys, not even sure if thsi is possible, but i will attempt to make this understandable. I am maknig a program in which an excel file needs to be opened. basically its something like this :
c.println ("are you a customer or an admin?");
status = c.readString
if (status.equalsIgnoreCase ("admin"))
c.println ("would you like to view or change the database files?");
if (status.equalsIgnoreCase ("view"))
//OPEN EXCEL FILE HERE FOR VIEWING! ! !
if (status.equalsIgnoreCase ("edit"))
//OPEN EXCEL FILE HERE FOR EDITING! ! !
some of this stuff may be off so i dont really need editing tips, i just need to know two things
1) how do i open an excel file to view?
2) is it possible to open an excel file and edit it? if so, how?
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
jeffgreco13

|
Posted: Tue Jun 10, 2008 8:24 am Post subject: Re: opening excel |
|
|
Java: |
public class openExcel {
public static void main(String [] args) {
try{
ProcessBuilder p=new ProcessBuilder("excel","path_to_excel_file");
p.start();
}catch(Exception e) {}
}
}
|
That's a main method if you notice. I'll let you play around and add it as a method you can call within your program.
|
|
|
|
|
 |
rto
|
Posted: Tue Jun 10, 2008 8:35 am Post subject: RE:opening excel |
|
|
i will most certainly give that a go, i will reply today durnig my fourth period (in first now) to let you know if it worked, thanks
|
|
|
|
|
 |
rto
|
Posted: Tue Jun 10, 2008 11:03 am Post subject: RE:opening excel |
|
|
errors:
line 1:
"public" is not a valid modifier for a local inner class
line 2:
The static method "main" is invalid, because it is enclosed in an inner class, "openExcel", located at C:/Users/john/Documents/Java/ISP.java:36.
line 4:
Type ProcessBuilder was not found
.. .. .. no clue
|
|
|
|
|
 |
Aziz

|
Posted: Tue Jun 10, 2008 11:08 am Post subject: RE:opening excel |
|
|
You need some more understanding of Java if you don't understand that code.
Do you know what a class is, and a "main" method? And you'll need to know about importing. Also, google "java 6 ProcessBuilder" to find the javadoc for that class.
Another thing you could do is parse the Excel file youself. That's probably more complicated than it's worth, however.
Also,jeffgreco12, classes (especially in java), are named LikeThis not likeThis. It only convention, but it's like saying it's a convention not to rape little children.
|
|
|
|
|
 |
jeffgreco13

|
Posted: Tue Jun 10, 2008 11:28 am Post subject: Re: opening excel |
|
|
Taht's absolutely right aziz... i slipped up there.
You need to import the correct javadoc. Search on google like Aziz said and it will tell you which one.
Why don't you show us what code you have written already. Im guessing that the code you asked for is only going to be a part of a bigger program right?
|
|
|
|
|
 |
rto
|
Posted: Tue Jun 10, 2008 9:21 pm Post subject: Re: opening excel |
|
|
Alright, let me first specify this: i am no java wizard nor do i claim to be. this is my isp for my ICS3M course (grade 11 programming for those who do not know) and i need the assistance. here is the code:
Description: |
|
 Download |
Filename: |
ISP.java |
Filesize: |
2.35 KB |
Downloaded: |
130 Time(s) |
|
|
|
|
|
 |
Tony

|
Posted: Tue Jun 10, 2008 9:59 pm Post subject: RE:opening excel |
|
|
And this is exactly why it's a bad idea to teach with Java, skip the fundamentals of "class", "public", "main", but require the students to use all of the above anyway. Brilliant!
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Sponsor Sponsor

|
|
 |
rto
|
Posted: Tue Jun 10, 2008 10:18 pm Post subject: RE:opening excel |
|
|
helpful tony anyways, im goin to bed, thanks for the help guys, anything else will be excellent talk to ya tomorrow
|
|
|
|
|
 |
jeffgreco13

|
Posted: Wed Jun 11, 2008 8:56 am Post subject: Re: opening excel |
|
|
Have you tried inserting this code into a method?
Here try this:
Java: |
public runapp(String pathname, String app) {
try {
ProcessBuilder proce=new ProcessBuilder(app, pathname);
proce.start();
}
catch(Exception e) {}
}
|
Now out of practice, I want YOU to figure out how to implement this in your program.
Hint: you may need to run a new process each time
I did quickly write this without an IDE so if there's any errors let me know.
|
|
|
|
|
 |
|