Top > OOoBeanShell > Calc > mergevertical

MergeVertical Edit

import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XModel;
import drafts.com.sun.star.script.provider.XScriptContext;
import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.PropertyValue;
import com.sun.star.container.XNameContainer;
import com.sun.star.container.XNameAccess;
import com.sun.star.frame.XModel;
import com.sun.star.frame.XController;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.view.XSelectionSupplier;
import com.sun.star.util.XMergeable;
import com.sun.star.container.XEnumeration;
import com.sun.star.container.XEnumerationAccess;
import com.sun.star.sheet.XSpreadsheetDocument;
import com.sun.star.sheet.XSpreadsheets;
import com.sun.star.sheet.XSpreadsheet;
import com.sun.star.sheet.XCellRangeAddressable;
import com.sun.star.text.XText;
import com.sun.star.table.XCellRange;
import com.sun.star.table.XCell;
oDoc = XSCRIPTCONTEXT.getDocument();
xSpreadsheetModel = (XModel) UnoRuntime.queryInterface(XModel.class, oDoc);
xController = xSpreadsheetModel.getCurrentController();
xSel = (XSelectionSupplier) UnoRuntime.queryInterface(XSelectionSupplier.class, xController);
Object Selection = xSel.getSelection();
xServiceInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, Selection);
String Info = xServiceInfo.getImplementationName();
// horizontal_merge function is used to merge cellranges horizontally .
void horizontal_merge(mergearea) throws java.lang.Exception{
	xRangeAddr = (XCellRangeAddressable) UnoRuntime.queryInterface(XCellRangeAddressable.class, mergearea);
	aRangeAddress = xRangeAddr.getRangeAddress();
	int nRows = aRangeAddress.EndRow - aRangeAddress.StartRow;
	int nCols = aRangeAddress.EndColumn - aRangeAddress.StartColumn;
	xSelectedRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, mergearea);
	for(int i=0; i<=nCols; i++) {
		
		xHorizontalRange = xSelectedRange.getCellRangeByPosition( i, 0, i, nRows);
		xHorizontalMergeable = (XMergeable) UnoRuntime.queryInterface(XMergeable.class, xHorizontalRange);
		merged = xHorizontalMergeable.getIsMerged();
		if (merged) {
			xHorizontalMergeable.merge(false);
			xHorizontalMergeable.merge(true);
		} else {
			xHorizontalMergeable.merge(true);
		}
	}
}
if (Info.equals("ScCellRangeObj")) {
	horizontal_merge(Selection);
} else if (Info.equals("ScCellRangesObj")) {
	xEnumerationAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, Selection);
	xEnumeration = xEnumerationAccess.createEnumeration();
	while (xEnumeration.hasMoreElements()) {
		Object oCellRange = xEnumeration.nextElement();
		horizontal_merge(oCellRange);
	}
}
return 0;

Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup   Help   RSS of recent changes