search = new TextNavigation("SIMPLE", doc);
while (search.hasNext()) {
TextSelection item = (TextSelection) search.nextSelection();
TableSelection nextTableSelection=new TableSelection(item);
Table table=sourcedoc.getTableByName("Table1");
Cell cell = table.getCellByPosition(0, 0);
cell.setStringValue("SIMPLE");
Table newtable = nextTableSelection.replaceWithTable(table);
Assert.assertNotNull(newtable);
Assert.assertEquals(1, newtable.getHeaderColumnCount());
Assert.assertEquals(1, newtable.getHeaderRowCount());
Assert.assertEquals(7 + 1, newtable.getRowCount());
Assert.assertEquals(5 + 1, newtable.getColumnCount());
cell = newtable.getCellByPosition(1, 1);
Assert.assertEquals("string", cell.getValueType());
}
//2 Task1, #1 at the start of original Paragraph, #2 replace original Paragraph
search = new TextNavigation("Task1", doc);
while (search.hasNext()) {
TextSelection item = (TextSelection) search.nextSelection();
TableSelection nextTableSelection=new TableSelection(item);
Table table=sourcedoc.getTableByName("Table2");
Table newtable = nextTableSelection.replaceWithTable(table);
Cell cell = newtable.getCellByPosition(0, 0);
cell.setStringValue("From Source Table2");
Assert.assertNotNull(newtable);
Assert.assertEquals(1, newtable.getHeaderColumnCount());
Assert.assertEquals(1, newtable.getHeaderRowCount());
Assert.assertEquals(10 + 1, newtable.getRowCount());
Assert.assertEquals(4 + 1, newtable.getColumnCount());
cell = newtable.getCellByPosition(1, 1);
Assert.assertEquals("float", cell.getValueType());
}
//1 RESS%>, #1 at the end of original Paragraph,
search = new TextNavigation("RESS%>", doc);
while (search.hasNext()) {
TextSelection item = (TextSelection) search.nextSelection();
TableSelection nextTableSelection=new TableSelection(item);
Table table=sourcedoc.getTableByName("Table3");
Table newtable = nextTableSelection.replaceWithTable(table);
Cell cell = newtable.getCellByPosition(0, 0);
cell.setStringValue("From Source Table3");
Assert.assertNotNull(newtable);
Assert.assertEquals(5, newtable.getRowCount());
Assert.assertEquals(3, newtable.getColumnCount());
}
try {
doc.save(ResourceUtilities.newTestOutputFile("TestTableSelectionResult.odt"));