JavaScript macro reference

I want to build a simple Calc macro to do currency conversion, but I can’t find almost any information or tutorials.

Where is the JavaScript macro language documentation? What functions are available? How can I make an HTTP request?

You’ll find more documentation on using LibreOffice Basic or Python… I cannot recall seeing a JavaScript tutorial around the last couple of years.

Good luck!

That is rather dumbfounding. Why does LO even support JavaScript if it’s undocumented?

Hello,

This may provide you with some information - click here.

Edit 6/9/17:

Sorry about not providing what you wanted initially. I’ll admit I know a little about Java and even less about Javascript (can run one). As other things on my list, this was one to try.

As @komma4 related there is little on tutorials. So I went about it in a different way. Using a provided LO sample and MRI. Mri showed me the class needed for a particular step and also linked me to specific AOO API (full reference here). The LO equivalent is here. Using that, I was able to create this (my very first) working JavaScript:

// When this script is run on an existing spreadsheet,
// the value 2 will be placed in cell A1 of the first sheet
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);

//get the document object from the scripting context
oDoc = XSCRIPTCONTEXT.getDocument();
//get the XSpreadsheetDocument interface from the document
xSDoc = UnoRuntime.queryInterface(XSpreadsheetDocument, oDoc);
//get the XIndexAccess interface used to access each sheet
xSheetsIndexAccess = UnoRuntime.queryInterface(XIndexAccess, xSDoc.getSheets());

//get sheet 0
xSheet = xSheetsIndexAccess.getByIndex(0);
//get the XCellRange interface used to access a cell
xCll = UnoRuntime.queryInterface(XCellRange,xSheet);
//get Cell A1
xCellA1 = xCll.getCellByPosition(0,0);
//get the XCell interface used to access a cell
xC = UnoRuntime.queryInterface(XCell,xCellA1);
xC.setValue(22);

Just a simple script which places the the value 22 in cell A1 on the first sheet. The only point is that all the information is available but you have to piece it together yourself. Agreeably not the best of situations.

I also found the following which may be of help: JavaScript Message Box.

No offense meant by the by the “If this answers…”. Habit when I see low karma. 50% don’t even respond at all. At least you took the time to respond even when it wasn’t what you wanted.

I’ve asked about JavaScript API documentation, not the Java SDK reference.

Also, I’ve been on StackExchange since 2009, and I know how to accept an answer :slight_smile: