Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. to open an excel file and write

to open an excel file and write

Scheduled Pinned Locked Moved Java
15 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    prithaa
    wrote on last edited by
    #1

    Hello Is there an article to open an excel file and write through jxl files. Every time I try to write into excel file a new file is created instead of opening the old file. Pritha

    L 1 Reply Last reply
    0
    • P prithaa

      Hello Is there an article to open an excel file and write through jxl files. Every time I try to write into excel file a new file is created instead of opening the old file. Pritha

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      prithaa wrote:

      Is there an article to open an excel file

      Quite possibly, have you tried a Google search?

      prithaa wrote:

      a new file is created instead of opening the old file.

      Without seeing your code I don't think we can guess what you may be doing wrong. [edit] This method[^] is probably what you are looking for. [/edit]

      speaking as ...

      P 1 Reply Last reply
      0
      • L Lost User

        prithaa wrote:

        Is there an article to open an excel file

        Quite possibly, have you tried a Google search?

        prithaa wrote:

        a new file is created instead of opening the old file.

        Without seeing your code I don't think we can guess what you may be doing wrong. [edit] This method[^] is probably what you are looking for. [/edit]

        speaking as ...

        P Offline
        P Offline
        prithaa
        wrote on last edited by
        #3

        thanks but the above link is not opening my problem was the following

        InputStream inp = new FileInputStream("d:/Writefile.xls");
        WorkbookSettings ws = new WorkbookSettings();
        Workbook wb = Workbook.getWorkbook(inp, ws);
        Sheet sheet = wb.getSheet(0);
        //Cell cells[] = sheet.getRow(0);
        //Cell cell = cells[0];
        //String cellContents = cell.getContents();
        //Modify the cellContents here
        //Write the output to a file
        Number number;
        number = new Number(0, 0, 453.25, times);
        ((WritableSheet) sheet).addCell(number);
        wb.close();

        The above code doesnt add the cell to the given file just opens the file.I get DispatchUnCaughtException for the line

        ((WritableSheet) sheet).addCell(number);

        Thanks for the reply Pritha

        L 1 Reply Last reply
        0
        • P prithaa

          thanks but the above link is not opening my problem was the following

          InputStream inp = new FileInputStream("d:/Writefile.xls");
          WorkbookSettings ws = new WorkbookSettings();
          Workbook wb = Workbook.getWorkbook(inp, ws);
          Sheet sheet = wb.getSheet(0);
          //Cell cells[] = sheet.getRow(0);
          //Cell cell = cells[0];
          //String cellContents = cell.getContents();
          //Modify the cellContents here
          //Write the output to a file
          Number number;
          number = new Number(0, 0, 453.25, times);
          ((WritableSheet) sheet).addCell(number);
          wb.close();

          The above code doesnt add the cell to the given file just opens the file.I get DispatchUnCaughtException for the line

          ((WritableSheet) sheet).addCell(number);

          Thanks for the reply Pritha

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Looking at the documentation (this link works for me[^]) it would suggest that you need to create a WritableWorkbook[^] and within that create a WritableSheet[^]. Casting a Sheet to a WritableSheet will not change the underlying object; it is still a (read-only) Sheet.

          speaking as ...

          P 1 Reply Last reply
          0
          • L Lost User

            Looking at the documentation (this link works for me[^]) it would suggest that you need to create a WritableWorkbook[^] and within that create a WritableSheet[^]. Casting a Sheet to a WritableSheet will not change the underlying object; it is still a (read-only) Sheet.

            speaking as ...

            P Offline
            P Offline
            prithaa
            wrote on last edited by
            #5

            thanks Richard but a

            WritableWorkbook creates a new workbook and has no method which opens a workbook

            Pritha

            L 1 Reply Last reply
            0
            • P prithaa

              thanks Richard but a

              WritableWorkbook creates a new workbook and has no method which opens a workbook

              Pritha

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              This method[^] creates one. May I suggest you go through all the documentation to check which methods are required to create the objects you are trying to work with.

              speaking as ...

              P 1 Reply Last reply
              0
              • L Lost User

                This method[^] creates one. May I suggest you go through all the documentation to check which methods are required to create the objects you are trying to work with.

                speaking as ...

                P Offline
                P Offline
                prithaa
                wrote on last edited by
                #7

                thanks for the article but i cant still open a writableworkbook .i can write on a new

                workbook

                but cant write on an existing workbook I didnt find any method doing that either in writableworkbook regards Pritha

                A L 2 Replies Last reply
                0
                • P prithaa

                  thanks for the article but i cant still open a writableworkbook .i can write on a new

                  workbook

                  but cant write on an existing workbook I didnt find any method doing that either in writableworkbook regards Pritha

                  A Offline
                  A Offline
                  Anil Kumar 23
                  wrote on last edited by
                  #8

                  Check this article ... may be of some help for your purpose Read and write to excel files in java

                  1 Reply Last reply
                  0
                  • P prithaa

                    thanks for the article but i cant still open a writableworkbook .i can write on a new

                    workbook

                    but cant write on an existing workbook I didnt find any method doing that either in writableworkbook regards Pritha

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    prithaa wrote:

                    thanks for the article

                    I did not provide one, I wonder what you have been looking at.

                    prithaa wrote:

                    but i cant still open a writableworkbook

                    Did you follow my advice and read all the documentation in the link I gave you? It clearly shows how to create a writeable workbook from an existing file.

                    speaking as ...

                    P 1 Reply Last reply
                    0
                    • L Lost User

                      prithaa wrote:

                      thanks for the article

                      I did not provide one, I wonder what you have been looking at.

                      prithaa wrote:

                      but i cant still open a writableworkbook

                      Did you follow my advice and read all the documentation in the link I gave you? It clearly shows how to create a writeable workbook from an existing file.

                      speaking as ...

                      P Offline
                      P Offline
                      prithaa
                      wrote on last edited by
                      #10

                      yes i did read the link u sent and looked at the class writablework but there is no method which opens an existing .xls file Regards Pritha

                      L 1 Reply Last reply
                      0
                      • P prithaa

                        yes i did read the link u sent and looked at the class writablework but there is no method which opens an existing .xls file Regards Pritha

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        Sorry, previous link was not correct owing to HTML frame. However, I think [this one](http://jexcelapi.sourceforge.net/resources/javadocs/current/docs/jxl/Workbook.html#createWorkbook\(java.io.File, jxl.Workbook, jxl.WorkbookSettings))[[^](http://jexcelapi.sourceforge.net/resources/javadocs/current/docs/jxl/Workbook.html#createWorkbook\(java.io.File, jxl.Workbook, jxl.WorkbookSettings))] is the best you will get.

                        speaking as ...

                        P 1 Reply Last reply
                        0
                        • L Lost User

                          Sorry, previous link was not correct owing to HTML frame. However, I think [this one](http://jexcelapi.sourceforge.net/resources/javadocs/current/docs/jxl/Workbook.html#createWorkbook\(java.io.File, jxl.Workbook, jxl.WorkbookSettings))[[^](http://jexcelapi.sourceforge.net/resources/javadocs/current/docs/jxl/Workbook.html#createWorkbook\(java.io.File, jxl.Workbook, jxl.WorkbookSettings))] is the best you will get.

                          speaking as ...

                          P Offline
                          P Offline
                          prithaa
                          wrote on last edited by
                          #12

                          thanks for replying

                          Workbook workbook = Workbook.getWorkbook(new File("d:/Writefile.xls"));
                          WritableWorkbook copy = Workbook.createWorkbook(new File("d:/Writefile1.xls"), workbook);
                          copy.write();
                          WritableSheet sheet = copy.getSheet("Report2");
                          Number number;
                          number = new Number(0, 0, 453.25, times);
                          sheet.addCell(number);
                          copy.write();
                          copy.close();

                          I want to open an existing file and add a cell to an existing sheet. The above code opens the file but the cell editing doesnt happen. Regards pritha

                          L 1 Reply Last reply
                          0
                          • P prithaa

                            thanks for replying

                            Workbook workbook = Workbook.getWorkbook(new File("d:/Writefile.xls"));
                            WritableWorkbook copy = Workbook.createWorkbook(new File("d:/Writefile1.xls"), workbook);
                            copy.write();
                            WritableSheet sheet = copy.getSheet("Report2");
                            Number number;
                            number = new Number(0, 0, 453.25, times);
                            sheet.addCell(number);
                            copy.write();
                            copy.close();

                            I want to open an existing file and add a cell to an existing sheet. The above code opens the file but the cell editing doesnt happen. Regards pritha

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #13

                            Sorry, no idea why that's happening; I think you may need to re-check the documentation and work with your debugger.

                            speaking as ...

                            P 1 Reply Last reply
                            0
                            • L Lost User

                              Sorry, no idea why that's happening; I think you may need to re-check the documentation and work with your debugger.

                              speaking as ...

                              P Offline
                              P Offline
                              prithaa
                              wrote on last edited by
                              #14

                              Thankyou Richard for your help

                              L 1 Reply Last reply
                              0
                              • P prithaa

                                Thankyou Richard for your help

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #15

                                Just for the record, I have never used these packages[^]; all the information I gave you I found by using Google and reading the Javadocs.

                                speaking as ...

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups