Implementation of XSSFWorkbook#getSheet(String name).

Implementation of XSSFWorkbook#removeSheet.

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@614877 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ugo Cei 2008-01-24 14:09:34 +00:00
parent 0caa21e82b
commit 2150018bac
2 changed files with 32 additions and 3 deletions

View File

@ -250,7 +250,12 @@ public class XSSFWorkbook implements Workbook {
} }
public Sheet getSheet(String name) { public Sheet getSheet(String name) {
// TODO Auto-generated method stub CTSheet[] sheets = this.workbook.getSheets().getSheetArray();
for (int i = 0 ; i < sheets.length ; ++i) {
if (name.equals(sheets[i].getName())) {
return this.sheets.get(i);
}
}
return null; return null;
} }
@ -297,8 +302,8 @@ public class XSSFWorkbook implements Workbook {
} }
public void removeSheetAt(int index) { public void removeSheetAt(int index) {
// TODO Auto-generated method stub XSSFSheet sheet = this.sheets.remove(index);
this.workbook.getSheets().removeSheet(index);
} }
public void setBackupFlag(boolean backupValue) { public void setBackupFlag(boolean backupValue) {

View File

@ -90,4 +90,28 @@ public class TestXSSFWorkbook extends TestCase {
assertEquals(3, workbook.getNumberOfSheets()); assertEquals(3, workbook.getNumberOfSheets());
assertEquals("clonedsheet(1)", workbook.getSheetName(2)); assertEquals("clonedsheet(1)", workbook.getSheetName(2));
} }
public void testGetSheetByName() {
XSSFWorkbook workbook = new XSSFWorkbook();
Sheet sheet1 = workbook.createSheet("sheet1");
Sheet sheet2 = workbook.createSheet("sheet2");
assertSame(sheet1, workbook.getSheet("sheet1"));
assertSame(sheet2, workbook.getSheet("sheet2"));
assertNull(workbook.getSheet("nosheet"));
}
public void testRemoveSheetAt() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook();
Sheet sheet1 = workbook.createSheet("sheet1");
Sheet sheet2 = workbook.createSheet("sheet2");
Sheet sheet3 = workbook.createSheet("sheet3");
workbook.removeSheetAt(1);
assertEquals(2, workbook.getNumberOfSheets());
assertEquals("sheet3", workbook.getSheetName(1));
workbook.removeSheetAt(0);
assertEquals(1, workbook.getNumberOfSheets());
assertEquals("sheet3", workbook.getSheetName(0));
workbook.removeSheetAt(0);
assertEquals(0, workbook.getNumberOfSheets());
}
} }