Inserting values into Calc's cells with JS

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
jza
Posts: 239
Joined: Mon Nov 03, 2008 11:33 am
Location: Cancún, Mexico

Inserting values into Calc's cells with JS

Post by jza »

So been looking around for a macro that does the same as the python one, however, seems that import uno, unohelper was enough to be calling interfaces on python. Javascript seems that uses direct calling ot each interface. i would like to know how to insert data into Calc from Javascript including which modules do I need, I have been trying to do the following:

Code: Select all

importClass(Packages.com.sun.star.uno.UnoRuntime);
importClass(Packages.com.sun.star.sheet.XSpreadsheet);
importClass(Packages.com.sun.star.table.CellContentType);
importClass(Packages.com.sun.star.frame.XModel);

oDoc = UnoRuntime.queryInterface(XModel,XSCRIPTCONTEXT.getInvocationContext());
if ( !oDoc )
  oDoc = XSCRIPTCONTEXT.getDocument();
xSpread = UnoRuntime.queryInterface(XSpreadsheetDocument,oDoc);
xCell = xSpread.getCellRangeByName("E2");
xCell.Value(34););
However a few questions:
- Which interface to import for the cells, and the cells content?
- XSpreadSheet seems to not be correctly instantiated.
- How to instantiate the cell, is a Shee/Row/Range needed for that, or will getDocument() already instantiate everything (sheet, cell)?
- How to get current cell location.

Update Been looking around this examples these examples. But still no luck on trying to fit them into the code. So far XSpreadSheet and XCelllRange are there but not correctly declared.
AOO 4.1.1 on Arch Linux
Post Reply