@Test
public void testAppendAndRemoveSheet() {
try {
SpreadsheetDocument document = SpreadsheetDocument.loadDocument(ResourceUtilities
.getTestResourceAsStream(TEST_FILE_NAME));
Table table = document.appendSheet("Sheet4");
Assert.assertEquals("Sheet4", table.getTableName());
table = document.appendSheet(document.getSheetByName("Sheet1"), "Sheet5");
Assert.assertEquals("Sheet5", table.getTableName());
document.save(ResourceUtilities.newTestOutputFile("Output_"+TEST_FILE_NAME));
//reload
document = SpreadsheetDocument.loadDocument(ResourceUtilities.getTestResourceAsStream("Output_"+TEST_FILE_NAME));
document.removeSheet(4);
Assert.assertNull(document.getSheetByName("Sheet5"));
document.removeSheet(3);
Assert.assertNull(document.getSheetByName("Sheet4"));
//data table from difference document.
document = SpreadsheetDocument.loadDocument(ResourceUtilities.getTestResourceAsStream(TEST_FILE_NAME));
Table sheet1 = document.getSheetByName("Sheet1");
SpreadsheetDocument document1 = SpreadsheetDocument.newSpreadsheetDocument();
table = document1.appendSheet(sheet1, "SheetA");
Assert.assertEquals(sheet1.getCellByPosition("E3").getDisplayText(), table.getCellByPosition("E3").getDisplayText());
document1.save(ResourceUtilities.newTestOutputFile("Output2_"+TEST_FILE_NAME));
} catch (Exception e) {
Logger.getLogger(SpreadsheetTest.class.getName()).log(Level.SEVERE, null, e);
Assert.fail(e.getMessage());
}