1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package fvt.uno.sc.rowcolumn; 23 24 import static org.junit.Assert.*; 25 26 import java.util.ArrayList; 27 import java.util.Arrays; 28 import java.util.Collection; 29 30 import org.junit.After; 31 import org.junit.AfterClass; 32 import org.junit.Before; 33 import org.junit.BeforeClass; 34 import org.junit.Test; 35 import org.junit.runner.RunWith; 36 import org.junit.runners.Parameterized; 37 import org.junit.runners.Parameterized.Parameters; 38 39 import org.openoffice.test.common.Testspace; 40 import org.openoffice.test.uno.UnoApp; 41 42 import com.sun.star.beans.XPropertySet; 43 import com.sun.star.container.XIndexAccess; 44 import com.sun.star.lang.XComponent; 45 import com.sun.star.sheet.XSpreadsheet; 46 import com.sun.star.sheet.XSpreadsheetDocument; 47 import com.sun.star.sheet.XSpreadsheets; 48 import com.sun.star.table.XCellRange; 49 import com.sun.star.table.XCell; 50 import com.sun.star.uno.Type; 51 import com.sun.star.uno.UnoRuntime; 52 import com.sun.star.util.XMergeable; 53 54 /** 55 * Check the content input in cell 56 * @author test 57 * 58 */ 59 60 public class CellMerge { 61 62 UnoApp unoApp = new UnoApp(); 63 XSpreadsheetDocument scDocument = null; 64 XComponent scComponent = null; 65 66 @Before setUp()67 public void setUp() throws Exception { 68 unoApp.start(); 69 } 70 71 @After tearDown()72 public void tearDown() throws Exception { 73 unoApp.closeDocument(scComponent); 74 unoApp.close(); 75 } 76 77 @Test testCellMerge()78 public void testCellMerge() throws Exception { 79 80 String sheetname = "sheet1"; 81 scComponent = unoApp.newDocument("scalc"); 82 scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent); 83 XSpreadsheets spreadsheets = scDocument.getSheets(); 84 Object sheetObj = spreadsheets.getByName(sheetname); 85 XSpreadsheet sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); 86 87 // Select A1 and input "12" 88 XCell cell = sheet.getCellByPosition(0, 0); 89 cell.setValue(12); 90 91 // Get cell range A1:B1 by position - (column, row, column, row) 92 XCellRange CellRange = sheet.getCellRangeByPosition( 0, 0, 1, 0 ); 93 //XCellRange CellRange = sheet.getCellRangeByName("A1:B1"); 94 95 // Merge cell range A1:B1 into one cell 96 XMergeable xMerge = (XMergeable) UnoRuntime.queryInterface(XMergeable.class, CellRange); 97 xMerge.merge(true); 98 99 // Verify if the cell range A1:B1 is completely merged 100 assertEquals("Verify if the cell range A1:B1 is completely merged",true, xMerge.getIsMerged()); 101 102 // Undo Merge cell range A1:B1 into one cell 103 xMerge.merge(false); 104 105 // Verify if the cell range A1:B1 is no longer merged 106 assertEquals("Verify if the cell range A1:B1 is no longer merged",false, xMerge.getIsMerged()); 107 108 } 109 110 } 111