Results 1 to 3 of 3
  1. #1
    jaryszek is offline Member
    Join Date
    Apr 2017
    Posts
    10
    Rep Power
    0

    Default Set up workbook in APACHE POI

    Hi Guys,

    i am using apache poi and have code like this:

    Java Code:
    import java.io.File;
    import java.io.IOException;
    import java.util.jar.Attributes.Name;
    
    import org.apache.poi.EncryptedDocumentException;
    import org.apache.poi.hssf.util.CellReference;
    import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
    import org.apache.poi.sl.usermodel.Sheet;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.WorkbookFactory;
    
    public class WorkbookCreate {
    
    	public static void main(String[] args) {
    		
    	    // setup code
    	    String cname = "TestName";
    	    
    	    org.apache.poi.ss.usermodel.Workbook wb = null;
    		try {
    			wb = WorkbookFactory.create(new File("/Workbook/src/Variable2.xlsm"));
    		} catch (EncryptedDocumentException | InvalidFormatException | IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    I have Variable2.xlsm and error is FileNotFound.

    Przechwytywanie.PNG

    can you please help me why?

    Best,
    Jacek

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,189
    Rep Power
    12

    Default Re: Set up workbook in APACHE POI

    I am unfamiliar with the POI API. However, have you looked at the WorkBookFactory API to see if there is a current directory method? Assuming you are running this from your favorite IDE, you need to ensure that your path is correct and that the file name is correct. So try to display the current directory using the API at hand. Then adjust the path accordingly.

    Also, since no package name is shown in your code and you didn't include the package name in the path, I must assume you are using the default package (i.e no package). This should be okay but then it could also be causing an issue. And using the default package is not considered good practice.

    Regards,
    Jim
    Last edited by jim829; 05-18-2018 at 05:03 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    jaryszek is offline Member
    Join Date
    Apr 2017
    Posts
    10
    Rep Power
    0

    Default Re: Set up workbook in APACHE POI

    Thank you Jim,

    this code (with full path) is working like a charm!


    Java Code:
    	    org.apache.poi.ss.usermodel.Workbook wb = null;
    		try {
    			 wb = WorkbookFactory.create(new File("C:\\Users\\admin\\Desktop\\Example Variable3.xlsm"));
    		} catch (EncryptedDocumentException | InvalidFormatException | IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    Best,
    JAcek

Similar Threads

  1. get Bytes from XSSF workbook
    By haiderali in forum Apache POI
    Replies: 3
    Last Post: 04-30-2014, 12:59 PM
  2. Replies: 11
    Last Post: 10-08-2013, 08:34 AM
  3. Java to Open Excel Workbook
    By jo15765 in forum New To Java
    Replies: 11
    Last Post: 08-09-2013, 04:55 PM
  4. Open an Excel workbook
    By ch7787 in forum New To Java
    Replies: 5
    Last Post: 07-20-2010, 05:20 PM
  5. Replies: 0
    Last Post: 11-15-2008, 07:29 AM

Posting Permissions

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