You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2013/01/10 06:04:18 UTC

[Bug 54399] New: Sheet index (-1) is out of range when rename sheet

https://issues.apache.org/bugzilla/show_bug.cgi?id=54399

            Bug ID: 54399
           Summary: Sheet index (-1) is out of range when rename sheet
           Product: POI
           Version: 3.9
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
          Assignee: dev@poi.apache.org
          Reporter: paulvancingel@gmail.com
    Classification: Unclassified

Created attachment 29838
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=29838&action=edit
XLSX file that fails sheet rename.

For one particular spreadsheet, renaming a sheet returns 
java.lang.IllegalArgumentException: Sheet index (-1) is out of range (0..1)

    at
org.apache.poi.xssf.usermodel.XSSFWorkbook.validateSheetIndex(XSSFWorkbook.java:1043)
    at
org.apache.poi.xssf.usermodel.XSSFWorkbook.getSheetName(XSSFWorkbook.java:876)
    at
org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook.getSheetNameByExternSheet(XSSFEvaluationWorkbook.java:135)
    at
org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils$1.getSheetNameByExternSheet(XSSFFormulaUtils.java:81)
    at
org.apache.poi.ss.formula.ptg.ExternSheetNameResolver.prependSheetName(ExternSheetNameResolver.java:42)
    at
org.apache.poi.ss.formula.ptg.Area3DPtg.toFormulaString(Area3DPtg.java:100)
    at
org.apache.poi.ss.formula.FormulaRenderer.toFormulaString(FormulaRenderer.java:92)
    at
org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils.updateName(XSSFFormulaUtils.java:143)
    at
org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils.updateSheetName(XSSFFormulaUtils.java:97)
    at
org.apache.poi.xssf.usermodel.XSSFWorkbook.setSheetName(XSSFWorkbook.java:1230)

Code is:

import org.apache.poi.ss.usermodel.*;
import java.io.*;

FileInputStream fileInputStream = new FileInputStream(filePath);  
Workbook workbook = WorkbookFactory.create(fileInputStream);  

System.out.println("sheets:" + workbook.getNumberOfSheets());

for (int i = 0; i < workbook.getNumberOfSheets(); i++) {  
  System.out.println("i:" + i);
  workbook.setSheetName(i, "Sheet" + (i + 1));
}  
fileInputStream.close();  

FileOutputStream fileOutputStream = new FileOutputStream(filePath); 
workbook.write(fileOutputStream);
fileOutputStream.close();  

This outputs 
sheets:1
i:0


Tested on POI versions 3.8 and 3.9.

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

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


[Bug 54399] Sheet index (-1) is out of range when rename sheet

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54399

--- Comment #1 from Dominik Stadler <do...@gmx.at> ---
The error happens at a point where the external references are resolved in
order to adjust all formulas/references for the new sheet-name.
FormularParser.createAreaRefParseNode() tries to read the external sheet index,
but does not find the referenced external sheets and thus ends up using -1. 

I still lack details of how it is supposed to work, though, to say if this is
somehow expected here or an invalid .xlsx or really a bug in POI...

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

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


[Bug 54399] Sheet index (-1) is out of range when rename sheet

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54399

Paul van Cingel <pa...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |paulvancingel@gmail.com
                 OS|                            |All

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

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