summaryrefslogtreecommitdiffstats
path: root/scripting/examples/beanshell/Calc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /scripting/examples/beanshell/Calc
parentInitial commit. (diff)
downloadlibreoffice-upstream.tar.xz
libreoffice-upstream.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripting/examples/beanshell/Calc')
-rw-r--r--scripting/examples/beanshell/Calc/CopyRange.bsh39
-rw-r--r--scripting/examples/beanshell/Calc/FixView.bsh34
-rw-r--r--scripting/examples/beanshell/Calc/InsertSheet.bsh25
-rw-r--r--scripting/examples/beanshell/Calc/ProtectSheet.bsh30
-rw-r--r--scripting/examples/beanshell/Calc/SelectCell.bsh30
-rw-r--r--scripting/examples/beanshell/Calc/parcel-descriptor.xml2
6 files changed, 160 insertions, 0 deletions
diff --git a/scripting/examples/beanshell/Calc/CopyRange.bsh b/scripting/examples/beanshell/Calc/CopyRange.bsh
new file mode 100644
index 000000000..d1e7a49f1
--- /dev/null
+++ b/scripting/examples/beanshell/Calc/CopyRange.bsh
@@ -0,0 +1,39 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.frame.XModel;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.sheet.XCellAddressable;
+import com.sun.star.sheet.XCellRangeAddressable;
+import com.sun.star.table.CellAddress;
+import com.sun.star.table.CellRangeAddress;
+import com.sun.star.sheet.XCellRangeMovement;
+
+oDoc = UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext());
+if ( oDoc == null )
+ oDoc = XSCRIPTCONTEXT.getDocument();
+
+XSpreadsheetDocument xDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class,oDoc);
+XSpreadsheets xSheets = xDoc.getSheets();
+XIndexAccess xSheetsIA = UnoRuntime.queryInterface(XIndexAccess.class, xSheets);
+XSpreadsheet xSheet = UnoRuntime.queryInterface(com.sun.star.sheet.XSpreadsheet.class, xSheetsIA.getByIndex(0));
+
+XCellRangeAddressable xAddr1 = UnoRuntime.queryInterface(XCellRangeAddressable.class, xSheet.getCellRangeByName("A1:A10") );
+CellRangeAddress source = xAddr1.getRangeAddress();
+
+XCellAddressable xAddr2 = UnoRuntime.queryInterface(XCellAddressable.class, xSheet.getCellRangeByName("B1").getCellByPosition( 0, 0 ) );
+CellAddress target = xAddr2.getCellAddress();
+
+XCellRangeMovement xCRM = UnoRuntime.queryInterface(XCellRangeMovement.class, xSheet);
+xCRM.copyRange(target, source);
+
+return 0;
diff --git a/scripting/examples/beanshell/Calc/FixView.bsh b/scripting/examples/beanshell/Calc/FixView.bsh
new file mode 100644
index 000000000..4ea2c62f9
--- /dev/null
+++ b/scripting/examples/beanshell/Calc/FixView.bsh
@@ -0,0 +1,34 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.frame.XModel;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.sheet.XViewFreezable;
+import com.sun.star.sheet.XViewPane;
+
+oDoc = UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext());
+if ( oDoc == null )
+ oDoc = XSCRIPTCONTEXT.getDocument();
+
+XSpreadsheetDocument xDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class,oDoc);
+XSpreadsheets xSheets = xDoc.getSheets();
+XIndexAccess xSheetsIA = UnoRuntime.queryInterface(XIndexAccess.class, xSheets);
+XSpreadsheet xSheet = UnoRuntime.queryInterface(com.sun.star.sheet.XSpreadsheet.class, xSheetsIA.getByIndex(0));
+
+XViewFreezable xFreeze = UnoRuntime.queryInterface(XViewFreezable.class, oDoc.getCurrentController() );
+xFreeze.freezeAtPosition(2, 3);
+
+XViewPane xViewPane = UnoRuntime.queryInterface(XViewPane.class, oDoc.getCurrentController() );
+xViewPane.setFirstVisibleColumn(12);
+xViewPane.setFirstVisibleRow(149);
+
+return 0;
diff --git a/scripting/examples/beanshell/Calc/InsertSheet.bsh b/scripting/examples/beanshell/Calc/InsertSheet.bsh
new file mode 100644
index 000000000..ef68f9b3e
--- /dev/null
+++ b/scripting/examples/beanshell/Calc/InsertSheet.bsh
@@ -0,0 +1,25 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.frame.XModel;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.lang.XMultiServiceFactory;
+
+oDoc = UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext());
+if ( oDoc == null )
+ oDoc = XSCRIPTCONTEXT.getDocument();
+
+XSpreadsheetDocument xDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class,oDoc);
+XSpreadsheets xSheets = xDoc.getSheets();
+
+xSheets.insertNewByName("First new sheet", (short)0);
+xSheets.insertNewByName("Second new sheet", (short)1);
+
+return 0;
diff --git a/scripting/examples/beanshell/Calc/ProtectSheet.bsh b/scripting/examples/beanshell/Calc/ProtectSheet.bsh
new file mode 100644
index 000000000..eea3bd511
--- /dev/null
+++ b/scripting/examples/beanshell/Calc/ProtectSheet.bsh
@@ -0,0 +1,30 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.frame.XModel;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.util.XProtectable;
+
+oDoc = UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext());
+if ( oDoc == null )
+ oDoc = XSCRIPTCONTEXT.getDocument();
+
+XSpreadsheetDocument xDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, oDoc);
+XSpreadsheets xSheets = xDoc.getSheets();
+XIndexAccess xSheetsIA = UnoRuntime.queryInterface(XIndexAccess.class, xSheets);
+XSpreadsheet xSheet = UnoRuntime.queryInterface(XSpreadsheet.class, xSheetsIA.getByIndex(0));
+XProtectable xProtectable = UnoRuntime.queryInterface(XProtectable.class, xSheet);
+xProtectable.protect("myPassword");
+
+//xProtectable.unprotect("myPassword");
+
+return 0;
diff --git a/scripting/examples/beanshell/Calc/SelectCell.bsh b/scripting/examples/beanshell/Calc/SelectCell.bsh
new file mode 100644
index 000000000..7d8f5a381
--- /dev/null
+++ b/scripting/examples/beanshell/Calc/SelectCell.bsh
@@ -0,0 +1,30 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.frame.XModel;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.view.XSelectionSupplier;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.table.XCellRange;
+
+oDoc = UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext());
+if ( oDoc == null )
+ oDoc = XSCRIPTCONTEXT.getDocument();
+
+XSpreadsheetDocument xDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class,oDoc);
+XSpreadsheets xSheets = xDoc.getSheets();
+XIndexAccess xSheetsIA = UnoRuntime.queryInterface(XIndexAccess.class, xSheets);
+XSpreadsheet xSheet = UnoRuntime.queryInterface(com.sun.star.sheet.XSpreadsheet.class, xSheetsIA.getByIndex(0));
+XCellRange xResultRange = xSheet.getCellRangeByName("B20");
+XSelectionSupplier xSel = UnoRuntime.queryInterface(XSelectionSupplier.class, oDoc.getCurrentController());
+xSel.select(xResultRange);
+
+return 0;
diff --git a/scripting/examples/beanshell/Calc/parcel-descriptor.xml b/scripting/examples/beanshell/Calc/parcel-descriptor.xml
new file mode 100644
index 000000000..155d53c9b
--- /dev/null
+++ b/scripting/examples/beanshell/Calc/parcel-descriptor.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><parcel xmlns:parcel="scripting.dtd" language="BeanShell">
+<script language="BeanShell"><locale lang="en"><displayname value="SelectCell.bsh"/><description>SelectCell.bsh</description></locale><logicalname value="SelectCell.bsh"/><functionname value="SelectCell.bsh"/></script><script language="BeanShell"><locale lang="en"><displayname value="InsertSheet.bsh"/><description>InsertSheet.bsh</description></locale><logicalname value="InsertSheet.bsh"/><functionname value="InsertSheet.bsh"/></script><script language="BeanShell"><locale lang="en"><displayname value="ProtectSheet.bsh"/><description>ProtectSheet.bsh</description></locale><logicalname value="ProtectSheet.bsh"/><functionname value="ProtectSheet.bsh"/></script><script language="BeanShell"><locale lang="en"><displayname value="CopyRange.bsh"/><description>CopyRange.bsh</description></locale><logicalname value="CopyRange.bsh"/><functionname value="CopyRange.bsh"/></script><script language="BeanShell"><locale lang="en"><displayname value="FixView.bsh"/><description>FixView.bsh</description></locale><logicalname value="FixView.bsh"/><functionname value="FixView.bsh"/></script></parcel> \ No newline at end of file