Connecting Tech Pros Worldwide Forums | Help | Site Map

how to open an ms office application either .doc,.xls,etc in java??

Newbie
 
Join Date: Jun 2007
Posts: 27
#1: Jun 20 '07
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
#2: Jun 20 '07

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
#3: Jun 20 '07

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
#4: Jun 20 '07

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
#5: Jun 20 '07

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
#6: Jun 20 '07

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
#7: Jun 20 '07

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
#8: Jun 20 '07

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
#9: Jun 20 '07

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
#10: Jun 20 '07

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:

Expand|Select|Wrap|Line Numbers
  1. String documentPath = "C:\\whateverThePathIs.doc";
  2. String command = "cmd /c start " + documentPath ;
  3. Runtime.getRuntime().exec(command);
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#11: Jun 20 '07

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:

Expand|Select|Wrap|Line Numbers
  1. String documentPath = "C:\\whateverThePathIs.doc";
  2. String command = "cmd /c start " + documentPath ;
  3. 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
#12: Jun 20 '07

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
#13: Jun 20 '07

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
#14: Jun 20 '07

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
#15: Jun 21 '07

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
#16: Jun 21 '07

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
#17: Jun 21 '07

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
#18: Jun 21 '07

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
#19: Jun 21 '07

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
#20: Jun 21 '07

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
#21: Jun 21 '07

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
#22: Jun 21 '07

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
#23: Jun 21 '07

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?

Reply