Export Excel Files with the Excel Exporter — Mendix 10

Mendix With Me
Mendix Community
8 min readAug 15, 2023

--

Export Excel Files with the Excel Exporter — Mendix 10 : Banner Image
Export Excel Files with the Excel Exporter — Mendix 10 : Banner Image

Exporting Excel files is something common in the day-to-day of most businesses. In this blog post, I will teach you how to export Excel files using the Excel Exporter module, in Mendix Studio Pro 10. This blog is based on a video I published on my YouTube channel (Mendix With Me), in which you can find similar videos on Mendix Development.

Prerequisites Marketplace modules

  • Mx Model Reflection
    Before starting the tutorial, ensure you have the Mx Model Reflection module installed in your project. If you don’t have it, you can install it using the following link. https://marketplace.mendix.com/link/component/69
Mx Model Reflection

Step by Step

Setting up Marketplace Modules

1 — Download the module Excel Exporter from the marketplace.

Excel Exporter Module — Marketplace
Excel Exporter Module — Marketplace

2 — Insert page “Excel_Document_Overview” into navigation (and MxObjects_Overview from Model Reflection if you don’t have it yet)

Menu Item creation — Add Excel Exporter page
Project Navigation

Setting up Security and the Domain Model

3 — Create a new project module called ExcelExport

Add new Module
ExcelExport module created

4 — Double-click on the module’s security and create a new module role called “Admin

New Module Role “Admin

5 — Go to the application’s security, select admin, and click on Edit roles. Give admin access to this role

App Security
Give permissions to a module

6 — In the ExcelExport module, create an ExcelDocument Entity as a Generalization of $FileDocument

Create ExcelDocument Entity

7 — Select the Access Rules tab and give permissions to the user role “Admin”.

Access Rules of ExcelDocument
Access Rule creation

8 — Create another entity called ProjectExport with the same attributes as the entity that you want to export the data.

Create ProjectExport Entity

9 — Select the Access Rules tab and give permissions to the user roles.

Give Permissions to module role

10 — Add an association between ExcelExport and ProjectExport. This association should be 1 to * (one to many)

Add an association between ExcelExport and ProjectExport

11 — Double click on the association and select “Delete ‘ProjectExport’ object(s) as well” under “On Delete of ‘ExcelDocument’ object”

Change association behaviour

Creating the Logic

12 — Create a folder for each entity as such:

Folder structure for ExcelDocument
Folder structure for ProjectExport

13 — Create a microflow called ACT_ProjectExport_ExportList inside the “ProjectExport/Microflows/ACT” folder

Create a microflow called ACT_ProjectExport_ExportList

14 — Inside the microflow, add a retrieve action. Select as a source “From Database” and choose the entity “MxTemplate”. As a constraint write “[Name = ‘Projects’]” (The “Projects” can be changed for what makes more sense in your own project)

Retrieve of MxTemplate Settings

15 — Add a decision to check if $MxTemplate is not empty ($MxTemplate != empty)

Decision to check if MxTemplate exists

16 — Add a Create Object action. Select as Entity “ExcelDocument” from the ExcelExport Module. Click on New and select the “DeleteAfterDownload” attribute. Set the value as “true”.

Create ExcelDocument

17 — Create a new list. As an entity use “ProjectExport” from ExcelExport Module and change the list name to ProjectExportList.

Create ProjectExportList

18 — Add a new Retrieve action to the microflow with the entity from where you want to export the data. As an example, we will select “Project”.

Retrieve all projects

19 — Now it is necessary to iterate throughout the list. To do so, add a Loop action and select the list we just retrieved.

Create and iterate throught a loop

20 — Inside the loop, add a new create object action. Select as an Entity “ProjectExport” from the ExcelExport Module. Fill all the entity attributes with the data from the iterator.

Create a ProjectExport object to export

21 — After the attribute values, fill the association with the ExcelDocument object.

Add association and fill the value with NewExcelDocument

22 — Add a change list action. Select “ProjectExportList” and use the object we just created as a value.

Change the List inside the loop

23 — Outside the loop, drag and drop a commit object action. Select the list called “ProjectExportList”.

Commit ProjectExportList

24 — Go to microflow properties and give access to the module role “admin”.

Microflow Properties

25 — Save and go to the App Module -> Marketplace Modules -> XLSReport -> UseMe Folder and Select “GenerateReport” microflow.

Find GenerateReport microflow

26 — Right-click on the microflow and click Duplicate. Right Click on the duplicated microflow and move to ExcelExport Module -> ExcelDocument/Microflows/SUB folder and rename it to SUB_ExcelDocument_GenerateReport

Duplicate microflow
Move and Rename to SUB_ExcelDocument_GenerateReport

27 — Inside the microflow, delete the create CustomExcel action. Regarding the parameters, add a new one with a data type object and with ExcelDocument as an entity.

Change GenerateExcel microflow

28 — Double-click on the java action “GenerateExcel”. Change the input values to the following objects:
Template object: $Template
Output Document: $ExcelDocument
Input Object: $ExcelDocument

Modify GenerateExcelDoc Java Action

29 — Go to microflow properties and give access to the module role “admin”.

Give permissions to Admin

30 — Go back to the ACT_ProjectExport_ExportList microflow and add at the end the SUB_ExcelDocument_GenerateReport. Double-click on the SUB and fill in the parameter values.

Add SUB to the end to the ACT
Fill parameters values

31 — In your overview page, add a new microflow button and select ACT_ProjectExport_ExportList microflow.
Change the caption to “Export” and the icon to the export icon.

Create a new Export button on the Overview page
Export button Details

Configuring the App at runtime

32 — After running the project, click on the Model Reflection page located on the menu.

Navigation

33 — Select “ExcelExport” and “XLSReport” Modules. Then, “Click to Refresh” in order to synchronize all entities and microflows.

MX Model Reflection page
Sync all entities and microflows of checked modules

34 — On the menu, click on the Excel Exporter page and Select the New button.

Create new template

35 — Create a new template by filling the fields with the following values and click “Save and Next”:
Document Type: Excel 2007 and higher
Filename: Projects
Input object: ExcelExport.ExcelDocument

New Template page details

36 — Select a date format for the “Date time export format” field

Define a date format

37 — In Worksheets, click new and fill all the fields with the data that you see on the image below.

Create new Worksheets
Worksheet details

38 — Click on the “New” button inside the “Column data” tab. A popup will appear, in which we can fill in the column number, and name and select the attribute we want to see exported. It is important that the first column has the number 0 instead of 1.

New Column data object detail

39 — Create all the columns you need for your export.

Worksheet columns to export

Testing the Export Function

40 — Go back to the overview page and click on the “Export” button.
After the download is finished, you can open the file and all your projects will be available.

Overview page export button
File download
Excel File

Join Me on Discord!

This is the end of the tutorial. Thank you for reading this far :)

I’m creating a Mendix community on Discord to make life easier for devs. You can ask questions, help other people, and have access to all the tutorials.
If you want to be part of this community, you can do so through this invite.

Read More

From the Publisher -

Inspired by this article to bring your ideas to life with Mendix? Sign up for a free account! You’ll get instant access to the Mendix Academy, where you can start building your skills.

For more articles like this one, visit our Medium page. And you can find a wealth of instructional videos on our community YouTube page.

Speaking of our community, join us in our Slack community channel. We’d love to hear your ideas and insights!

--

--

Mendix With Me
Mendix Community

Ricardo Pereira: Certified Mendix Expert from Portugal 🇵🇹 | Founder of Mendix With Me community | Join us on Discord: discord.gg/YHre8dXz3q