Ask Your Question

JavaScript macro reference

asked 2017-06-06 19:39:03 +0200

dandv gravatar image

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?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2017-06-07 20:49:46 +0200

Ratslinger gravatar image

updated 2017-06-10 03:33:13 +0200


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

//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);

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.

edit flag offensive delete link more


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 :)

dandv gravatar imagedandv ( 2017-06-08 06:19:34 +0200 )edit

answered 2017-06-07 08:37:05 +0200

komma4 gravatar image

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!

edit flag offensive delete link more


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

dandv gravatar imagedandv ( 2017-06-08 06:20:20 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-06-06 19:39:03 +0200

Seen: 4,174 times

Last updated: Jun 10 '17