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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anubhav vij
    New Member
    • Jun 2007
    • 27

    #1

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

    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 .
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    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

    Comment

    • anubhav vij
      New Member
      • Jun 2007
      • 27

      #3
      plz provide me with the exact code plz.....


      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

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        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.

        Comment

        • anubhav vij
          New Member
          • Jun 2007
          • 27

          #5
          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 InputStreamRead er(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.re adLine()) != null) {
          System.out.prin tln(s);

          }

          fr.close();
          }
          }

          but this is not working....

          plz help me out.

          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.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            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 InputStreamRead er(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.re adLine()) != null) {
            System.out.prin tln(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.

            Comment

            • anubhav vij
              New Member
              • Jun 2007
              • 27

              #7
              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

              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.

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                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?

                Comment

                • anubhav vij
                  New Member
                  • Jun 2007
                  • 27

                  #9
                  yes sir,

                  at last u understood my problem.....

                  yes sir either open a .doc file or any extension using MS-OFFICE.

                  plz rply soon....

                  Originally posted by r035198x
                  Do you want to open a .doc file from a Java program so that it opens using Microsoft word?

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    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:

                    [CODE=java]String documentPath = "C:\\whateverTh ePathIs.doc";
                    String command = "cmd /c start " + documentPath ;
                    Runtime.getRunt ime().exec(comm and);[/CODE]

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #11
                      Originally posted by r035198x
                      You should still consider using something like poi.
                      This might work for you though:

                      [CODE=java]String documentPath = "C:\\whateverTh ePathIs.doc";
                      String command = "cmd /c start " + documentPath ;
                      Runtime.getRunt ime().exec(comm and);[/CODE]
                      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

                      Comment

                      • anubhav vij
                        New Member
                        • Jun 2007
                        • 27

                        #12
                        what if i m using LINUX as my OS????

                        nyways thanx for helping.....



                        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

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #13
                          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?

                          Comment

                          • anubhav vij
                            New Member
                            • Jun 2007
                            • 27

                            #14
                            i m using open office.org 2.0

                            Originally posted by r035198x
                            What are you using for viewing .doc files on Linux?

                            Comment

                            • anubhav vij
                              New Member
                              • Jun 2007
                              • 27

                              #15
                              nobody has rplyed me yet????


                              Originally posted by anubhav vij
                              i m using open office.org 2.0

                              Comment

                              Working...