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