<!-- Don't forget to update status.xml too! -->
<release version="3.5-beta6" date="2009-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">47089 - Fixed XSSFWorkbook.createSheet to properly increment sheetId</action>
<action dev="POI-DEVELOPERS" type="fix">46568 - Fixed XSLFPowerPointExtractor to properly process line breaks</action>
<action dev="POI-DEVELOPERS" type="fix">39056 - Fixed POIFSFileSystem to set CLSID of root when constructing instances from InputStream</action>
<action dev="POI-DEVELOPERS" type="fix">47054 - Fixed cloneStyleFrom to avoid exception when cloning styles of the same family</action>
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.5-beta6" date="2009-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">47089 - Fixed XSSFWorkbook.createSheet to properly increment sheetId</action>
<action dev="POI-DEVELOPERS" type="fix">46568 - Fixed XSLFPowerPointExtractor to properly process line breaks</action>
<action dev="POI-DEVELOPERS" type="fix">39056 - Fixed POIFSFileSystem to set CLSID of root when constructing instances from InputStream</action>
<action dev="POI-DEVELOPERS" type="fix">47054 - Fixed cloneStyleFrom to avoid exception when cloning styles of the same family</action>
CTSheet sheet = addSheet(sheetname);
- int sheetNumber = getNumberOfSheets() + 1;
+ int sheetNumber = 1;
+ for(XSSFSheet sh : sheets) sheetNumber = (int)Math.max(sh.sheet.getSheetId() + 1, sheetNumber);
+
XSSFSheet wrapper = (XSSFSheet)createRelationship(XSSFRelation.WORKSHEET, XSSFFactory.getInstance(), sheetNumber);
wrapper.sheet = sheet;
sheet.setId(wrapper.getPackageRelationship().getId());
assertEquals(2, st.getFills().size());
assertEquals(1, st.getBorders().size());
}
-
+
+ public void testIncrementSheetId() throws Exception {
+ XSSFWorkbook wb = getTestDataProvider().createWorkbook();
+ int sheetId = (int)wb.createSheet().sheet.getSheetId();
+ assertEquals(1, sheetId);
+ sheetId = (int)wb.createSheet().sheet.getSheetId();
+ assertEquals(2, sheetId);
+
+ //test file with gaps in the sheetId sequence
+ wb = getTestDataProvider().openSampleWorkbook("47089.xlsm");
+ int lastSheetId = (int)wb.getSheetAt(wb.getNumberOfSheets() - 1).sheet.getSheetId();
+ sheetId = (int)wb.createSheet().sheet.getSheetId();
+ assertEquals(lastSheetId+1, sheetId);
+ }
}