Posts

Showing posts with the label script

Javascript for LibreOffice scripting

Image
Now, a js example to run in OO Calc: importClass(Packages.com.sun.star.uno.UnoRuntime); importClass(Packages.com.sun.star.sheet.XSpreadsheetDocument); importClass(Packages.com.sun.star.container.XIndexAccess); importClass(Packages.com.sun.star.table.XCellRange); importClass(Packages.com.sun.star.table.XCell); documentRef = XSCRIPTCONTEXT.getDocument(); spreadsheetInterface = UnoRuntime.queryInterface(XSpreadsheetDocument, documentRef); allSheets = UnoRuntime.queryInterface(XIndexAccess, spreadsheetInterface.getSheets()); theSheet = allSheets.getByIndex(0); Cells = UnoRuntime.queryInterface(XCellRange,theSheet); cellA1 = Cells.getCellByPosition(0,0); theCell = UnoRuntime.queryInterface(XCell,cellA1); theCell.setFormula("Hello World"); // https://wiki.documentfoundation.org/images/f/f0/CG6212-CalcMacros.pdf   And here the result:  

VisualBasic scripting in LibreOffice

Image
 Here an example to run in Writer: Sub Hello Dim oDoc Dim sTextService$ Dim oCurs REM ThisComponent se refiere al documento actualmente activo oDoc = ThisComponent REM Verifica que este es un documento de texto sTextService = "com.sun.star.text.TextDocument" If NOT oDoc.supportsService(sTextService) Then MsgBox "This macro only works with a text document" Exit Sub End If REM obtiene la vista del cursor del controlador actual oCurs = oDoc.currentController.getViewCursor() REM Mueve el cursor al final del documento oCurs.gotoEnd(False) REM Inserta el texto “Hola” al final del documento oCurs.Text.insertString(oCurs, "Hello World", False) End Sub REM https://documentation.libreoffice.org/assets/Uploads/Documentation/es/GS52/PDF/GS5213-PrimerosPasosConMacros.pdf And the result is here:

BeanShell scripting in LibreOffice

Image
Here is a BeanShell script to xploit functionalities from LibreOffice spreadsheeat: import com.sun.star.uno.UnoRuntime; import com.sun.star.sheet.XSpreadsheetView; import com.sun.star.text.XText; import com.sun.star.sheet.XCellRangeData; // // Get active spreadsheet // model = XSCRIPTCONTEXT.getDocument(); controller = model.getCurrentController(); view = UnoRuntime.queryInterface(XSpreadsheetView.class, controller); sheet = view.getActiveSheet(); // // Create a TEXT CELL // // Get cell by position cell = sheet.getCellByPosition(0, 0); // Access the cell text cellText = UnoRuntime.queryInterface(XText.class, cell); // Get the text cursor of the cell text textCursor = cellText.createTextCursor(); // Insert a string in the cell through the text cursor and overwrite the cell content // Using 'false' as third parameter adds the inserted string cellText.insertString(textCursor, "BeanShell macro example", true); // // Access and modify VALUE CELLS // // Get cell by position...

How to execute Python scripts in Android

Image
First, you need to install QPython in your Android. To access to your Android console, you can use SSHDroid  (remote access) or Terminal Emulator  (local access). Python for Android depends from a lot bash scripts. You need use all of them to run it. Now, you need add to your PATH (configurable in init.environ.rc), python executable. Other option is create symbolic links of your apps to /system/bin, as follow: su mount -o rw,remount /system cd /system/bin ln -s /data/data/org.qpython.qpy/files/bin/end.sh  ln -s /data/data/org.qpython.qpy/files/bin/python-android5 ln -s /data/data/org.qpython.qpy/files/bin/init.sh ln -s /data/data/org.qpython.qpy/files/bin/qpython-android5.sh python Now you can run python on your console :) To execute a python script without calls to python, you must write on the first line of your script this line: #!/system/bin/python To execute the script, give it execution permission throught the console: chmod +x $NAME.py ...

Resource name without extension to use as variable in external tools on Eclipse

Image
In my last post about how to configure ns3 on Eclipse  I gave the file name through a string prompt variable ("${string_prompt}"). This method is bored, for this reason I searched, how to give the file name without the extension automatically. StartExplorer is a plugin for Eclipse and in their web, they mentioned the following: In addition, StartExplorer itself offers a few variables of its own. ${resource_name_without_extension} : File name or directory name of the resource, without path and without extension (that is, resource, without trailing dot) Also, the plugin Pathtool is another plugin with several variables. I  installed them using the MarketPlace client (see how to install marketplace on Eclipse CDT ), but the variable that I want didn't appear in the variable list. To automate the execution of my simulations, I created a bash script that calls waf (called wafEclipse) and parse the file name to remove the extension .cc This is the wafEclipse co...