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

    Default Read range name from Excel

    Hi Guys,

    I am total newbe but i have to know how to read named range in apache poi.

    I am trying only to read value for named range.

    I am using code like:

    Java Code:
    	public static void main(String[] args) throws IOException {
    		
    		
    	
    	    // setup code
    	   	    String cname = "TestName";
    	    
    	    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();
    		}
    		
    		int namedCellIdx = wb.getNameIndex("TestVariable");
    		
    		System.out.println(namedCellIdx);
    	    org.apache.poi.ss.usermodel.Name aNamedCell = wb.getNameAt(namedCellIdx);
    	    
    	    System.out.println(aNamedCell);
    
    	    }
    
    	}
    and my error is :

    Exception in thread "main" java.lang.IllegalArgumentException: Specified name index -1 is outside the allowable range (0..0).
    Can you help me how to fix this ?

    Best,
    Jacek
    Last edited by jaryszek; 05-19-2018 at 04:56 PM.

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

    Default Re: Read range name from Excel

    And my output is:

    Attachment 7369

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

    Default Re: Read range name from Excel

    In attachment please find my example workbook.

    I wnat to read named Range "Test" and "TestVariable".

    Best,
    Jacek
    Attached Files Attached Files

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

    Default Re: Read range name from Excel

    Anyone?

    Jacek

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

    Default Re: Read range name from Excel

    Normally, a few days is not too long to wait. But this forum has not been very active this year (not sure why). So you may need to try some other forums. But when cross-posting, let each forum know where you've posted as a courtesy to avoid duplication of responses.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

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

    Default Re: Read range name from Excel

    Hi Jim,

    thank you,
    can you recommend some other java forums? :)

    Best,
    Jacek

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

    Default Re: Read range name from Excel

    Try https://coderanch.com

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

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

    Default Re: Read range name from Excel

    thank you Jim!

    Strange, a lot of people is wathing this topic but nobody answers.

    Best,
    Jacek

  9. #9
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,965
    Rep Power
    7

    Default Re: Read range name from Excel

    What happened when you tried this: https://poi.apache.org/apidocs/org/a...odel/Name.html
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

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

Similar Threads

  1. Replies: 0
    Last Post: 07-17-2014, 04:18 AM
  2. Replies: 0
    Last Post: 02-21-2014, 11:04 AM
  3. Replies: 0
    Last Post: 11-01-2013, 07:17 AM
  4. How to read from excel?
    By ginger0001 in forum Apache POI
    Replies: 2
    Last Post: 04-02-2012, 10:50 AM
  5. Excel: How to sort a range?
    By Chris_X in forum Java Servlet
    Replies: 9
    Last Post: 11-22-2010, 01:24 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
  •