PowerPoint Integration in Mendix using Java

Akshay Donode
Mendix Community
Published in
4 min readFeb 9, 2021

In this blog is I will show you how to generate Power Point documents Mendix. This can be done using the Apache POI library and a Simple Json library. Data that should go into the PowerPoint is passed in Json format to the java action where Apache POI will be used to populate it in table format in a PowerPoint.

Introduction:

To generate the result in a PowerPoint document, we need to add java action as Mendix currently only supports .html, .pdf, .docx, .doc, .rtf and .odc typed documents only. To create a PowerPoint need to do the below three steps.

· Download dependent jars

· Create the Java action

· Create a microflow

1) Download dependent jars

Now let’s add the required jar files. You can download them from https://mvnrepository.com/. In this example, we downloaded Apache POI (4.1.2), json-simple jars (1.1.1), and org.json.jar (20160810). I placed those downloaded jars in userlib folder of the project (as shown in the screenshot below).

Jars of projects

2)Create Java Action:

Right click on module and create Java action or you can create it directly from the microflow.

Java Action

Open your new java action and click on ‘Add’ to add input parameters. For generating PowerPoint document need to pass a System.Filedocument object and Json data(name JsonData) as a string to java action as input parameter. This will return a Boolean to indicate whether PowerPoint is generated or not.

Adding input parameter in Java Action

3) Create a Microflow:

Create a microflow and get the response from REST Api after that need to create File object.

File Object

Image of Full Microflow.

Full image of microflow

After adding the java action to microflow need to map all the input parameters to java action.

Mapping input parameter to java action

After we have added the java action we need to deploy this project to Eclipse. Mendix by default supports Eclipse, however any Java Development IDE can be used to write the custom java code.

Deploying application to eclipse

After deploying the app for Eclipse we need to import the existing project and browse up to the Mendix application folder. If you don’t know where your project is created then you can find out from Mendix Studio pro. Just click on Project > Show Project Directory in Explorer. After opening the project in Eclipse expand the project in Project Explorer and then expand the javasource folder. Inside that you have to open the myfirstmodule.actions(in my application module name is myfirstmodule) folder inside that you will find java_action.java file just open that (This file is created by Mendix).

Line number 58 and 63 variables are the input parameter which already declared when we create Java action in Mendix studio pro.

Start writing java code but make sure to write between line number 66 and 69(between comments -// BEGIN USER CODE and // END USER CODE) otherwise you will get unnecessary error. You can write extra method/function between line number 80 and 81(between comments// BEGIN EXTRA CODE // END EXTRA CODE).

Java Code Sample:

Sample Java code

After completing our java code save the project and close Eclipse. Go back to Mendix studio pro and add the download file activity. Run the application locally and check the PowerPoint file.

Download File

Run the application locally and check the downloaded PowerPoint file.

Additional Tips:

• There is a need to modify java code according to the JSON structure.

• In the above example I passed the JSON data as a string in the input parameter.

If you have any query please reach out to me. Happy coding!!!

--

--