SelectCell.bsh 1.3 KB

123456789101112131415161718192021222324252627282930
  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.view.XSelectionSupplier;
  14. import com.sun.star.container.XIndexAccess;
  15. import com.sun.star.table.XCellRange;
  16. oDoc = UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext());
  17. if ( oDoc == null )
  18. oDoc = XSCRIPTCONTEXT.getDocument();
  19. XSpreadsheetDocument xDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class,oDoc);
  20. XSpreadsheets xSheets = xDoc.getSheets();
  21. XIndexAccess xSheetsIA = UnoRuntime.queryInterface(XIndexAccess.class, xSheets);
  22. XSpreadsheet xSheet = UnoRuntime.queryInterface(com.sun.star.sheet.XSpreadsheet.class, xSheetsIA.getByIndex(0));
  23. XCellRange xResultRange = xSheet.getCellRangeByName("B20");
  24. XSelectionSupplier xSel = UnoRuntime.queryInterface(XSelectionSupplier.class, oDoc.getCurrentController());
  25. xSel.select(xResultRange);
  26. return 0;