Browse Source

fixed XSSFWorkbook.createSheet to properly increment sheetId when sheetId sequence is not continious

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@768389 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_5_BETA6
Yegor Kozlov 15 years ago
parent
commit
8363279282

+ 1
- 0
src/documentation/content/xdocs/changes.xml View File

@@ -37,6 +37,7 @@

<!-- 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>

+ 1
- 0
src/documentation/content/xdocs/status.xml View File

@@ -34,6 +34,7 @@
<!-- 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>

+ 3
- 1
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java View File

@@ -453,7 +453,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X

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());

+ 14
- 1
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java View File

@@ -227,5 +227,18 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
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);
}
}

Loading…
Cancel
Save