Quantcast
Channel: Java Programming Forum - Learn Java Programming - Apache POI
Viewing all articles
Browse latest Browse all 120

Read range name from Excel

$
0
0
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:

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 :

Quote:

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

Viewing all articles
Browse latest Browse all 120

Trending Articles