Macro Examples


The following examples demonstrate possible uses for macros as well as their syntax.

Macros started by a spreadsheet function

Hiding/unhiding a row

In the example below, the two simple functions hide() and unhide() are shown. The hide() function sets the value in A1 to TRUE, while the unhide() function sets the value in A1 to FALSE.

These macros have been assigned to the buttons “Hide row” and “Unhide row”, as shown in the following screenshot:

The HIDEROW(A1) function in A3 reacts to the value in A1, either hiding or unhiding row 3.

Setting a border


Note: only the following border types are possible: top, bottom, left, right, out, ins_horiz, ins_vert, ins, all. The values are case-sensitive.

Setting a target cell

The function setCell() defines C8 as the target cell. If the target cell contains the value “locked”, then the content is deleted. If nothing is in C8, the value “locked” is written into the cell.

Getting a cell value from another worksheet

The function getcell() gets the value from Sheet2!B2 and writes it into cell C10 of the active sheet.

Exporting a workbook to the hard drive

The following code exports the workbook to the server’s hard drive.

savepath The file path for the exported workbook
type The file type of the export (XLSX for Excel 2010+ or WSS for Jedox)

The export mode.

0 = no snapshot
1 = full snapshot
2 = snapshot of OLAP formulas

Note: this code will export the file into a local folder on the server, so it may not be accessible to remote users. For this, you have to export into a folder in the Apache docroot, then dynamically create and display a link to the file. Not all folders on the file system are accessible for the Macro Engine, nor should they be; the open_basedir directive of the Macro Engine may prevent you from exporting to a specific folder.

Checking for “error” type

It is possible to check whether some resource (cell reference, named formula, or variable) currently holds a value of “error” type, such as #Value! or #N/A. For example, the following code is executed when a workbook is opened, checks if some variable currently holds an error value, and then initializes the variable to a fixed value:

Sending an email

The following code sends an email to a selected recipient:

Parameter Input Description
$to string/array The e-mail address or an array of recipient e-mail addresses.
$subject string The e-mail subject.
$body string The plaintext or HTML body of the message.
$from string The e-mail address of the sender.
$cc string/array The e-mail address or an array e-mail addresses of the recipient/s in CC.
$bcc string/array The e-mail address or an array e-mail addresses of the recipient/s in BCC.
$attachment string The path to the files you want to add to the attachment.

Macros started by a form element

The following macro examples will work only if the macro is started by a form element (combo box, check box, or button). They do not work when they are called as a spreadsheet function.

Displaying a popup message

Show_popup() gets the text of C4 and displays it in an info message box titled “Test”. Warning (“warn”) and error (“err”) messages are also available.

Executing a hyperlink

The code below will execute a hyperlink to a specific location:

Or, if the Hyperlink is present in some cell, you can simply refer to that cell:

Recalculating a spreadsheet
Logging out

Using system variables to connect to OLAP

In the Macro Engine, Jedox functions can be defined using an already-established OLAP session.

Instead of creating the following connection:

You can establish the connection as follows:

Rather than using a static user/role, this macro uses the actual user who is logged in, including their actual rights. 

An even better way to establish the connection is to also make the values for In-Memory DB host and port dynamic, to allow for portability of the code between varying Jedox environments: