Ask Your Question
0

JavaScript macro reference

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

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
1

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

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

Comments

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

dandv gravatar imagedandv ( 2017-06-08 06:20:20 +0100 )edit
1

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

Ratslinger gravatar image

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

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.

edit flag offensive delete link more

Comments

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 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 5,091 times

Last updated: Jun 10 '17