CopyRange.bsh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * This file is part of the LibreOffice project.
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. import com.sun.star.uno.UnoRuntime;
  9. import com.sun.star.frame.XModel;
  10. import com.sun.star.sheet.XSpreadsheetDocument;
  11. import com.sun.star.sheet.XSpreadsheet;
  12. import com.sun.star.sheet.XSpreadsheets;
  13. import com.sun.star.container.XIndexAccess;
  14. import com.sun.star.sheet.XCellAddressable;
  15. import com.sun.star.sheet.XCellRangeAddressable;
  16. import com.sun.star.table.CellAddress;
  17. import com.sun.star.table.CellRangeAddress;
  18. import com.sun.star.sheet.XCellRangeMovement;
  19. oDoc = UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext());
  20. if ( oDoc == null )
  21. oDoc = XSCRIPTCONTEXT.getDocument();
  22. XSpreadsheetDocument xDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class,oDoc);
  23. XSpreadsheets xSheets = xDoc.getSheets();
  24. XIndexAccess xSheetsIA = UnoRuntime.queryInterface(XIndexAccess.class, xSheets);
  25. XSpreadsheet xSheet = UnoRuntime.queryInterface(com.sun.star.sheet.XSpreadsheet.class, xSheetsIA.getByIndex(0));
  26. XCellRangeAddressable xAddr1 = UnoRuntime.queryInterface(XCellRangeAddressable.class, xSheet.getCellRangeByName("A1:A10") );
  27. CellRangeAddress source = xAddr1.getRangeAddress();
  28. XCellAddressable xAddr2 = UnoRuntime.queryInterface(XCellAddressable.class, xSheet.getCellRangeByName("B1").getCellByPosition( 0, 0 ) );
  29. CellAddress target = xAddr2.getCellAddress();
  30. XCellRangeMovement xCRM = UnoRuntime.queryInterface(XCellRangeMovement.class, xSheet);
  31. xCRM.copyRange(target, source);
  32. return 0;