https://bz.apache.org/bugzilla/show_bug.cgi?id=59214

            Bug ID: 59214
           Summary: java.lang.IllegalArgumentException: Sheet index (1) is
                    out of range (0..0)
           Product: POI
           Version: 3.14-FINAL
          Hardware: PC
            Status: NEW
          Severity: critical
          Priority: P2
         Component: HSSF
          Assignee: dev@poi.apache.org
          Reporter: aliyev.ja...@gmail.com

Created attachment 33692
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=33692&action=edit
This is the XLS file to test

I'm trying to get an active sheet of HSSFWorkbook, but always get
java.lang.IllegalArgumentException. 
Here is the code and the xls file to reproduce the problem. 

package org.apache.poi.mytest;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;

public class PoiTest {

    public PoiTest() {
    }

     @Test
     public void testIt() throws FileNotFoundException, IOException {
         FileInputStream fis = new FileInputStream("Fir.xls"); 
         Workbook wb = new HSSFWorkbook(fis);
        Iterator<Sheet> shIt = wb.sheetIterator();
        while (shIt.hasNext()) {  
            Sheet sheet = shIt.next();
            System.out.println("Sheet name = "+sheet.getSheetName());
        }
         Sheet sheet = wb.getSheetAt(wb.getActiveSheetIndex());           
     }
}

When you run, you'll get the following output.

------------- Standard Output ---------------
Sheet name = Module1
------------- ---------------- ---------------
Testcase: testIt(org.apache.poi.mytest.PoiTest):    Caused an ERROR
Sheet index (1) is out of range (0..0)
java.lang.IllegalArgumentException: Sheet index (1) is out of range (0..0)
    at
org.apache.poi.hssf.usermodel.HSSFWorkbook.validateSheetIndex(HSSFWorkbook.java:522)
    at
org.apache.poi.hssf.usermodel.HSSFWorkbook.getSheetAt(HSSFWorkbook.java:994)
    at
org.apache.poi.hssf.usermodel.HSSFWorkbook.getSheetAt(HSSFWorkbook.java:109)
    at org.apache.poi.mytest.PoiTest.testIt(PoiTest.java:30)

As you see, the Module1 is recognized as sheet, but active sheet's index=1,
although the workbook has only one sheet.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to