16fbc0818SLiu Zhe 26fbc0818SLiu Zhe 36fbc0818SLiu Zhe 46fbc0818SLiu Zhe 5*eba4d44aSLiu Zhe package fvt.uno.sc.rowcolumn; 66fbc0818SLiu Zhe 76fbc0818SLiu Zhe import static org.junit.Assert.*; 86fbc0818SLiu Zhe 96fbc0818SLiu Zhe 106fbc0818SLiu Zhe import org.junit.After; 116fbc0818SLiu Zhe import org.junit.Before; 126fbc0818SLiu Zhe import org.junit.Test; 136fbc0818SLiu Zhe 146fbc0818SLiu Zhe import org.openoffice.test.uno.UnoApp; 156fbc0818SLiu Zhe 166fbc0818SLiu Zhe 176fbc0818SLiu Zhe import com.sun.star.lang.XComponent; 186fbc0818SLiu Zhe import com.sun.star.sheet.XSpreadsheet; 196fbc0818SLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument; 206fbc0818SLiu Zhe import com.sun.star.sheet.XSpreadsheets; 216fbc0818SLiu Zhe import com.sun.star.table.XCell; 226fbc0818SLiu Zhe import com.sun.star.uno.UnoRuntime; 236fbc0818SLiu Zhe import com.sun.star.table.XTableColumns; 246fbc0818SLiu Zhe import com.sun.star.table.XTableRows; 256fbc0818SLiu Zhe import com.sun.star.table.XColumnRowRange; 266fbc0818SLiu Zhe 276fbc0818SLiu Zhe /** 286fbc0818SLiu Zhe * Test insert or delete rows and columns 296fbc0818SLiu Zhe * @author test 306fbc0818SLiu Zhe * 316fbc0818SLiu Zhe */ 326fbc0818SLiu Zhe 336fbc0818SLiu Zhe public class InsertDeleteRowAndColumn { 346fbc0818SLiu Zhe 356fbc0818SLiu Zhe UnoApp unoApp = new UnoApp(); 366fbc0818SLiu Zhe XSpreadsheetDocument scDocument = null; 376fbc0818SLiu Zhe XComponent scComponent = null; 386fbc0818SLiu Zhe 396fbc0818SLiu Zhe @Before 406fbc0818SLiu Zhe public void setUp() throws Exception { 416fbc0818SLiu Zhe unoApp.start(); 426fbc0818SLiu Zhe } 436fbc0818SLiu Zhe 446fbc0818SLiu Zhe @After 456fbc0818SLiu Zhe public void tearDown() throws Exception { 466fbc0818SLiu Zhe unoApp.closeDocument(scComponent); 476fbc0818SLiu Zhe unoApp.close(); 486fbc0818SLiu Zhe } 496fbc0818SLiu Zhe 506fbc0818SLiu Zhe @Test 516fbc0818SLiu Zhe public void testInsertDeleteRows() throws Exception { 526fbc0818SLiu Zhe 536fbc0818SLiu Zhe String sheetname = "sheet1"; 546fbc0818SLiu Zhe scComponent = unoApp.newDocument("scalc"); 556fbc0818SLiu Zhe scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent); 566fbc0818SLiu Zhe XSpreadsheets spreadsheets = scDocument.getSheets(); 576fbc0818SLiu Zhe Object sheetObj = spreadsheets.getByName(sheetname); 586fbc0818SLiu Zhe 596fbc0818SLiu Zhe 606fbc0818SLiu Zhe XSpreadsheet sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); 616fbc0818SLiu Zhe XColumnRowRange xCRRange = (XColumnRowRange) UnoRuntime.queryInterface( XColumnRowRange.class, sheet ); 626fbc0818SLiu Zhe XTableRows xRows = xCRRange.getRows(); 636fbc0818SLiu Zhe 646fbc0818SLiu Zhe // Create a cell series "A2:A8" with the values 1 ... 7. 656fbc0818SLiu Zhe int nRow = 1; 666fbc0818SLiu Zhe for (int i = 1; i < 8; ++i) { 676fbc0818SLiu Zhe sheet.getCellByPosition( 0, nRow ).setValue( nRow ); 686fbc0818SLiu Zhe nRow += 1; 696fbc0818SLiu Zhe } 706fbc0818SLiu Zhe 716fbc0818SLiu Zhe //Insert a row between row 2 and row 3 726fbc0818SLiu Zhe xRows.insertByIndex( 2, 1 ); 736fbc0818SLiu Zhe 746fbc0818SLiu Zhe //Get value of cell A3 756fbc0818SLiu Zhe XCell cell = sheet.getCellByPosition(0, 2); 766fbc0818SLiu Zhe double checkvalue = 0.0; 776fbc0818SLiu Zhe 786fbc0818SLiu Zhe //Verify after insert row 796fbc0818SLiu Zhe assertEquals("Verify one new row inserted after Row 2",checkvalue, cell.getValue(),0); 806fbc0818SLiu Zhe 816fbc0818SLiu Zhe //Delete the row 3 and row 4 826fbc0818SLiu Zhe xRows.removeByIndex( 2, 2 ); 836fbc0818SLiu Zhe 846fbc0818SLiu Zhe //Get value of cell A3 and A4 856fbc0818SLiu Zhe XCell cellA3 = sheet.getCellByPosition(0, 2); 866fbc0818SLiu Zhe XCell cellA4 = sheet.getCellByPosition(0, 3); 876fbc0818SLiu Zhe double checkvalueA3 = 3.0; 886fbc0818SLiu Zhe double checkvalueA4 = 4.0; 896fbc0818SLiu Zhe 906fbc0818SLiu Zhe //Verify after delete row3 and row4 916fbc0818SLiu Zhe assertEquals("Verify tow rows deleted the value of row 3",checkvalueA3, cellA3.getValue(),0); 926fbc0818SLiu Zhe assertEquals("Verify tow rows deleted the value of row 4",checkvalueA4, cellA4.getValue(),0); 936fbc0818SLiu Zhe 946fbc0818SLiu Zhe } 956fbc0818SLiu Zhe 966fbc0818SLiu Zhe @Test 976fbc0818SLiu Zhe public void testInsertDeleteColumns() throws Exception { 986fbc0818SLiu Zhe 996fbc0818SLiu Zhe String sheetname = "sheet1"; 1006fbc0818SLiu Zhe scComponent = unoApp.newDocument("scalc"); 1016fbc0818SLiu Zhe scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent); 1026fbc0818SLiu Zhe XSpreadsheets spreadsheets = scDocument.getSheets(); 1036fbc0818SLiu Zhe Object sheetObj = spreadsheets.getByName(sheetname); 1046fbc0818SLiu Zhe 1056fbc0818SLiu Zhe 1066fbc0818SLiu Zhe XSpreadsheet sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); 1076fbc0818SLiu Zhe XColumnRowRange xCRRange = (XColumnRowRange) UnoRuntime.queryInterface( XColumnRowRange.class, sheet ); 1086fbc0818SLiu Zhe XTableColumns xColumns = xCRRange.getColumns(); 1096fbc0818SLiu Zhe 1106fbc0818SLiu Zhe // Create a cell series "A2:A8" with the values 1 ... 7. 1116fbc0818SLiu Zhe int nRow = 1; 1126fbc0818SLiu Zhe for (int i = 1; i < 8; ++i) { 1136fbc0818SLiu Zhe sheet.getCellByPosition( 1, nRow ).setValue( nRow ); 1146fbc0818SLiu Zhe nRow += 1; 1156fbc0818SLiu Zhe } 1166fbc0818SLiu Zhe 1176fbc0818SLiu Zhe //Insert a row between row 2 and row 3 1186fbc0818SLiu Zhe xColumns.insertByIndex( 0, 1 ); 1196fbc0818SLiu Zhe 1206fbc0818SLiu Zhe //Get value of cell C2 1216fbc0818SLiu Zhe XCell cell = sheet.getCellByPosition(2, 1); 1226fbc0818SLiu Zhe double checkvalue = 1.0; 1236fbc0818SLiu Zhe 1246fbc0818SLiu Zhe //Verify after insert row 1256fbc0818SLiu Zhe assertEquals("Verify if one new column inserted after Column A",checkvalue, cell.getValue(),0); 1266fbc0818SLiu Zhe 1276fbc0818SLiu Zhe //Delete the row 3 and row 4 1286fbc0818SLiu Zhe xColumns.removeByIndex( 0, 1 ); 1296fbc0818SLiu Zhe 1306fbc0818SLiu Zhe //Get value of cell A3 and A4 1316fbc0818SLiu Zhe XCell cellA3 = sheet.getCellByPosition(1, 2); 1326fbc0818SLiu Zhe XCell cellA4 = sheet.getCellByPosition(1, 3); 1336fbc0818SLiu Zhe double checkvalueA3 = 2.0; 1346fbc0818SLiu Zhe double checkvalueA4 = 3.0; 1356fbc0818SLiu Zhe 1366fbc0818SLiu Zhe //Verify after delete row3 and row4 1376fbc0818SLiu Zhe assertEquals("Verify after tow rows deleted, the value of A3",checkvalueA3, cellA3.getValue(),0); 1386fbc0818SLiu Zhe assertEquals("Verify after tow rows deleted, the value of A4",checkvalueA4, cellA4.getValue(),0); 1396fbc0818SLiu Zhe 1406fbc0818SLiu Zhe } 1416fbc0818SLiu Zhe 1426fbc0818SLiu Zhe } 1436fbc0818SLiu Zhe 144