Results 1 to 12 of 12
Like Tree1Likes
  • 1 Post By gimbal2

Thread: Java to Open Excel Workbook

  1. #1
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Java to Open Excel Workbook

    What would the java syntax & needed imports be to open an Excel workbook?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,425
    Rep Power
    20

    Default Re: Java to Open Excel Workbook

    To open it? Check out the API for java.awt.Desktop.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Re: Java to Open Excel Workbook

    Quote Originally Posted by DarrylBurke View Post
    To open it? Check out the API for java.awt.Desktop.

    db
    So something like this:
    Java Code:
    imports java.awt.Desktop
    imports java.io.File;
    impots java.io.IOException;
    
    Desktop dk = null;
    dk = Desktop.getDesktop();
    dk.open(new File("MyWorkbook.xlsx"));
    My IDE is telling me the word open -- cannotfind symbol, symbol: class File
    Last edited by jo15765; 08-08-2013 at 11:31 PM. Reason: Full code with imports

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,165
    Rep Power
    6

    Default Re: Java to Open Excel Workbook

    Good time to learn how to fix such problems. Its pretty vital to you being able to achieve anything in Java land.

    Try this. Google:

    java 7 File

    Result:

    File (Java Platform SE 7 )

    Now at the very top you see the package that the class is in: java.io. With that piece of information you should know what import statement to add.

    Of course your IDE can also do it for you almost automatically, but its better to learn how to find your information first before you let tools do the work for you.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Re: Java to Open Excel Workbook

    Quote Originally Posted by gimbal2 View Post
    Good time to learn how to fix such problems. Its pretty vital to you being able to achieve anything in Java land.

    Try this. Google:

    java 7 File

    Result:

    File (Java Platform SE 7 )

    Now at the very top you see the package that the class is in: java.io. With that piece of information you should know what import statement to add.

    Of course your IDE can also do it for you almost automatically, but its better to learn how to find your information first before you let tools do the work for you.

    Thank you Thank you! I am using NetBeans for the 1st time attempting to create some JavaForms, and while it is similar to the ADT I am more comfortable with it is different (for me at least) at the same time.

  6. #6
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Re: Java to Open Excel Workbook

    Now my next issue is that when I attempt to run my form, I get a Run Project Error. It says Form1.Form1_Test wasn't found in Form1 project. Select the main class: <No main classes found>

  7. #7
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,165
    Rep Power
    6

    Default Re: Java to Open Excel Workbook

    Can't help you with that. When you decide to forget about tools and create everything from scratch yourself, perhaps then I can lend a help when you get stuck with the code.
    DarrylBurke likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Re: Java to Open Excel Workbook

    Quote Originally Posted by gimbal2 View Post
    Can't help you with that. When you decide to forget about tools and create everything from scratch yourself, perhaps then I can lend a help when you get stuck with the code.
    Thank you for the assistance.
    I enjoy the GUI's as for me still being a novice help 95% of the time. But when I get stuck on silly things like this, when I know I have valid code is when it get's annoying for me :)

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,425
    Rep Power
    20

    Default Re: Java to Open Excel Workbook

    Believe me, it's easier to learn to hand-code a GUI than to sort out those 'silly things' without adequate knowledge of Swing coding.

    Oh, and any time you get errors you don't have valid code.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  10. #10
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Re: Java to Open Excel Workbook

    So I finally have my code working to open an excel workbook on a local machine. But I can not get it to open an excel workbook on a network, I always get an error of The system can not find the file specified. Is this the correct syntax to open a file on a network in java
    Java Code:
    Desktop.open(new File("\\\\ServerName\\Folder\\Main\\Data\\Weekly\\Employee\\EmployeeInfo.xls"))'

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,425
    Rep Power
    20

    Default Re: Java to Open Excel Workbook

    A network resource isn't a file.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  12. #12
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Re: Java to Open Excel Workbook

    Quote Originally Posted by DarrylBurke View Post
    A network resource isn't a file.

    db
    Argh! Upon my further googling, it looks like this task is going to be quite difficult as the files needed are on a network folder, AND there are spaces in the directory tree of where I need to navigate!

Similar Threads

  1. Replies: 3
    Last Post: 06-12-2012, 05:47 PM
  2. Replies: 2
    Last Post: 04-06-2011, 05:38 PM
  3. Replies: 3
    Last Post: 02-23-2011, 08:25 PM
  4. Open an Excel workbook
    By ch7787 in forum New To Java
    Replies: 5
    Last Post: 07-20-2010, 06:20 PM
  5. Replies: 0
    Last Post: 03-11-2008, 03:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •