How to Export Excel File/Report with Excel Exporter - Mendix 10

mendixwithme

MendixWithMe

Posted on August 15, 2023

How to Export Excel File/Report with Excel Exporter - Mendix 10


The need to export excel files is something common in the day to day of a business. In this blog post, I will teach you how to export excel files using Excel Exporter module.

Prerequisites Marketplace modules

  • Mx Model Reflection Before starting the tutorial, make sure that 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

Image description

Step by Step

1 - Download the module Excel Exporter from the marketplace.

Image description

2 - Insert page "Excel_Document_Overview" into navigation (and MxObjects_Overview from Model Reflection if you don't have it yet)

Image description

Image description

3 - Create a new project module called ExcelExport

Image description

Image description

4 - Double click on the module security and create a new module role called "Admin"

Image description

5 - Go to application security, select admin and click in Edit roles. Give admin access to this role

Image description

Image description

Image description

6 - In ExcelExport module, create ExcelDocument Entity as a Generalization of FileDocument

Image description

Image description

7 - Select Access Rules tab and give permissions to the user role "Admin".

Image description

Image description

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

Image description

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

Image description

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

Image description

11 - Double click on the association and select "Delete 'ProjectExport' object(s) as well" under "On Delete of 'ExcelDocument' object"

Image description

12 -  Create a folder to each entity as such:

Image description

Image description

13 - Create a microflow called ACT_ProjectExport_ExportList inside the "ProjectExport/Microflows/ACT" folder

Image description

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)

Image description

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

Image description

16 - Add a Create Object action. Select as Entity "ExcelDocument" from ExcelExport Module. Click in New and select "DeleteAfterDownload" attribute. Set the value as "true".

Image description

17 - Create a new list. As entity use "ProjectExport" from ExcelExport Module and change the list name to ProjectExportList.

Image description

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".

Image description

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

Image description

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

Image description

21 - After the attributes values, fill the association with the ExcelDocument object.

Image description

22 - Add a change list action. Select "ProjectExportList" and use the object we just created as a value.

Image description

23 - Outside the loop, drag and drop a commit object action. Select the list called "ProjectExportList".

Image description

24 - Go to microflow properties and give access to the module role "admin".

Image description

Image description

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

Image description

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

Image description

Image description

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

Image description

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

Image description

29 - Go to microflow properties and give access to the module role "admin".

Image description

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 the parameter values.

Image description

Image description

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.

Image description

Image description

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

Image description

33 - Select "ExcelExport" and "XLSReport" Modules. Then, “Click to Refresh” in order to synchronise all entities and microflows.

Image description

Image description

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

Image description

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

Image description

36 - Select a date format for the "Date time export format" field

Image description

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

Image description

Image description

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

Image description

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

Image description

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.

Image description

Image description

Image description

This is the end of the tutorial. 
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.
Discord: https://discord.gg/YHre8dXz3q

From the publisher
If you enjoyed this article you can find more on our Medium page. For great videos, you can visit our Youtube page.
Are you interested in getting more involved with our community? Join us in our Discord Community Channel.

💖 💪 🙅 🚩
mendixwithme
MendixWithMe

Posted on August 15, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related