how to open an ms office application either .doc,.xls,etc in java?? | Newbie | | Join Date: Jun 2007
Posts: 27
| | |
how to open an ms office application either .doc,.xls,etc in java??
i m new at java so don't know how to open a .doc or .txt file using java .
| | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: how to open an ms office application either .doc,.xls,etc in java?? Quote:
Originally Posted by anubhav vij how to open an ms office application either .doc,.xls,etc in java??
i m new at java so don't know how to open a .doc or .txt file using java . Opening a .txt is easy. Read a basic io tutorial that talks about FileReader or Scanner. For .doc or .xls, it requires a bit more processing since the data can take many different forms. If you're new to Java you might not want to do this yourself yet. You can use third party packages like poi, lucene, itext e.t.c
| | Newbie | | Join Date: Jun 2007
Posts: 27
| | | re: how to open an ms office application either .doc,.xls,etc in java??
plz provide me with the exact code plz..... Quote:
Originally Posted by r035198x Opening a .txt is easy. Read a basic io tutorial that talks about FileReader or Scanner. For .doc or .xls, it requires a bit more processing since the data can take many different forms. If you're new to Java you might not want to do this yourself yet. You can use third party packages like poi, lucene, itext e.t.c | | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: how to open an ms office application either .doc,.xls,etc in java?? Quote:
Originally Posted by anubhav vij plz provide me with the exact code plz..... Read the tutorial and write the code yourself. We can assist if you get problems with it not to write codes for you without you putting any effort. See the guidelines.
| | Newbie | | Join Date: Jun 2007
Posts: 27
| | | re: how to open an ms office application either .doc,.xls,etc in java??
import java.io.*;
class fileinput {
public static void main(String[] args) throws Exception {
FileWriter Fin=new FileWriter("/home/cipa/Documents/anubhav.doc");
String str;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
str=(String) br.readLine();
Fin.write(str);
Fin.close();
FileReader fr=new FileReader("/home/cipa/Documents/anubhav.doc");
BufferedReader br1=new BufferedReader(fr);
String s;
while((s=br1.readLine()) != null) {
System.out.println(s);
}
fr.close();
}
}
but this is not working....
plz help me out. Quote:
Originally Posted by r035198x Read the tutorial and write the code yourself. We can assist if you get problems with it not to write codes for you without you putting any effort. See the guidelines. | | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: how to open an ms office application either .doc,.xls,etc in java?? Quote:
Originally Posted by anubhav vij import java.io.*;
class fileinput {
public static void main(String[] args) throws Exception {
FileWriter Fin=new FileWriter("/home/cipa/Documents/anubhav.doc");
String str;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
str=(String) br.readLine();
Fin.write(str);
Fin.close();
FileReader fr=new FileReader("/home/cipa/Documents/anubhav.doc");
BufferedReader br1=new BufferedReader(fr);
String s;
while((s=br1.readLine()) != null) {
System.out.println(s);
}
fr.close();
}
}
but this is not working....
plz help me out. 1.) When posting code please use code tags.
2.) What do you mean by it's not working? Error message, exception?
3.) Read my first reply again.
| | Newbie | | Join Date: Jun 2007
Posts: 27
| | | re: how to open an ms office application either .doc,.xls,etc in java??
there is no error no exception.....
it just creates a file anubhav.doc at backend but doesn't open it.....
i wanna open the file at front and then write in it....
now u got me....i think Quote:
Originally Posted by r035198x 1.) When posting code please use code tags.
2.) What do you mean by it's not working? Error message, exception?
3.) Read my first reply again. | | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: how to open an ms office application either .doc,.xls,etc in java?? Quote:
Originally Posted by anubhav vij there is no error no exception.....
it just creates a file anubhav.doc at backend but doesn't open it.....
i wanna open the file at front and then write in it....
now u got me....i think Do you want to open a .doc file from a Java program so that it opens using Microsoft word?
| | Newbie | | Join Date: Jun 2007
Posts: 27
| | | re: how to open an ms office application either .doc,.xls,etc in java??
yes sir,
at last u understood my problem.....
yes sir either open a .doc file or any extension using MS-OFFICE.
plz rply soon.... Quote:
Originally Posted by r035198x Do you want to open a .doc file from a Java program so that it opens using Microsoft word? | | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: how to open an ms office application either .doc,.xls,etc in java?? Quote:
Originally Posted by anubhav vij yes sir,
at last u understood my problem.....
yes sir either open a .doc file or any extension using MS-OFFICE.
plz rply soon.... You should still consider using something like poi.
This might work for you though: - String documentPath = "C:\\whateverThePathIs.doc";
-
String command = "cmd /c start " + documentPath ;
-
Runtime.getRuntime().exec(command);
| | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: how to open an ms office application either .doc,.xls,etc in java?? Quote:
Originally Posted by r035198x You should still consider using something like poi.
This might work for you though: - String documentPath = "C:\\whateverThePathIs.doc";
-
String command = "cmd /c start " + documentPath ;
-
Runtime.getRuntime().exec(command);
In case you're wondering, this only works if you're using windows OS and if you have associated a program with the .doc extension
| | Newbie | | Join Date: Jun 2007
Posts: 27
| | | re: how to open an ms office application either .doc,.xls,etc in java??
what if i m using LINUX as my OS????
nyways thanx for helping..... Quote:
Originally Posted by r035198x In case you're wondering, this only works if you're using windows OS and if you have associated a program with the .doc extension | | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: how to open an ms office application either .doc,.xls,etc in java?? Quote:
Originally Posted by anubhav vij what if i m using LINUX as my OS????
nyways thanx for helping..... What are you using for viewing .doc files on Linux?
| | Newbie | | Join Date: Jun 2007
Posts: 27
| | | re: how to open an ms office application either .doc,.xls,etc in java??
i m using open office.org 2.0 Quote:
Originally Posted by r035198x What are you using for viewing .doc files on Linux? | | Newbie | | Join Date: Jun 2007
Posts: 27
| | | re: how to open an ms office application either .doc,.xls,etc in java??
nobody has rplyed me yet???? Quote:
Originally Posted by anubhav vij i m using open office.org 2.0 | | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: how to open an ms office application either .doc,.xls,etc in java?? Quote:
Originally Posted by anubhav vij nobody has rplyed me yet???? Have you looked at the poi package like I suggested?
| | Newbie | | Join Date: Jun 2007
Posts: 27
| | | re: how to open an ms office application either .doc,.xls,etc in java??
yup i looked at it but didn't get nything.....
this is my code and is running perfectly...
class runExtApp{
public void runfunc(){
try{
Runtime.getRuntime().exec("oowriter");
}catch(IOException e){ //end try 5
System.err.println(e);
}//end try catch block 7
}//end runfunc
}//end main class runExtApp Quote:
Originally Posted by r035198x Have you looked at the poi package like I suggested? | | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: how to open an ms office application either .doc,.xls,etc in java?? Quote:
Originally Posted by anubhav vij yup i looked at it but didn't get nything.....
this is my code and is running perfectly...
class runExtApp{
public void runfunc(){
try{
Runtime.getRuntime().exec("oowriter");
}catch(IOException e){ //end try 5
System.err.println(e);
}//end try catch block 7
}//end runfunc
}//end main class runExtApp If it's running perfectly then where's the problem?
| | Newbie | | Join Date: Jun 2007
Posts: 27
| | | re: how to open an ms office application either .doc,.xls,etc in java??
no problem buddy i just posted this code for future reference..and use for others...
thnx nyways
now help me out with other problem i have posted SWING APPLICATION. Quote:
Originally Posted by r035198x If it's running perfectly then where's the problem? | | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: how to open an ms office application either .doc,.xls,etc in java?? Quote:
Originally Posted by anubhav vij yup i looked at it but didn't get nything.....
this is my code and is running perfectly...
class runExtApp{
public void runfunc(){
try{
Runtime.getRuntime().exec("oowriter");
}catch(IOException e){ //end try 5
System.err.println(e);
}//end try catch block 7
}//end runfunc
}//end main class runExtApp So you got this working on Linux?
| | Newbie | | Join Date: Jun 2007
Posts: 27
| | | re: how to open an ms office application either .doc,.xls,etc in java??
yes sir ,
i got this working code for linux .... Quote:
Originally Posted by r035198x So you got this working on Linux? | | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: how to open an ms office application either .doc,.xls,etc in java?? Quote:
Originally Posted by anubhav vij yes sir ,
i got this working code for linux .... and where do you specify the name of the .doc file to open?
| | Newbie | | Join Date: Jun 2007
Posts: 27
| | | re: how to open an ms office application either .doc,.xls,etc in java??
no where this is to open the open office application using java and then saving the file there..... Quote:
Originally Posted by r035198x and where do you specify the name of the .doc file to open? |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,419 network members.
|