*DivideWithSpace [#k89af4c0] 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.container.XIndexAccess; import com.sun.star.frame.XController; import com.sun.star.lang.XServiceInfo; import com.sun.star.view.XSelectionSupplier; 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; import com.sun.star.sheet.XCellAddressable; 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(); if (Info.equals("ScCellRangeObj") || Info.equals("ScCellObj")) { xRangeAddr = (XCellRangeAddressable) UnoRuntime.queryInterface(XCellRangeAddressable.class, Selection); aRangeAddress = xRangeAddr.getRangeAddress(); int nSheet = aRangeAddress.Sheet; int nRows = aRangeAddress.EndRow - aRangeAddress.StartRow; int nCols = aRangeAddress.EndColumn - aRangeAddress.StartColumn; xSelectedRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, Selection); xSheetDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, oDoc); xSpreadsheets = xSheetDoc.getSheets(); xSheetIndexAcc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); Object sheet = xSheetIndexAcc.getByIndex(nSheet); xSpreadsheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheet); for (int i=0; i<=nRows; i++) { oCell = xSelectedRange.getCellByPosition(0, i); xCellAddr = (XCellAddressable) UnoRuntime.queryInterface(XCellAddressable.class, oCell); aCellAddr = xCellAddr.getCellAddress(); int nSColumn = aCellAddr.Column; int nSRow = aCellAddr.Row; // xCell = (XCell) UnoRuntime.queryInterface(XCell.class, oCell); xCellText = (XText) UnoRuntime.queryInterface(XText.class, oCell); sLocString = xCellText.getString(); sPartString = sLocString.split("\\s"); nCell = 0; for (int j=0; j<sPartString.length; j++) { if (! sPartString[j].equals("")) { oPartCell = xSpreadsheet.getCellByPosition(nSColumn + nCell, nSRow); xPartCellText = (XText) UnoRuntime.queryInterface(XText.class, oPartCell); xPartCellText.setString(sPartString[j]); nCell++; } } } } |