Export Excel Files with the Excel Exporter — Mendix 10
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
Step by Step
Setting up Marketplace Modules
1 — Download the module Excel Exporter from the marketplace.
2 — Insert page “Excel_Document_Overview” into navigation (and MxObjects_Overview from Model Reflection if you don’t have it yet)
Setting up Security and the Domain Model
3 — Create a new project module called ExcelExport
4 — Double-click on the module’s security and create a new module role called “Admin”
5 — Go to the application’s security, select admin, and click on Edit roles. Give admin access to this role
6 — In the ExcelExport module, create an ExcelDocument Entity as a Generalization of $FileDocument
7 — Select the Access Rules tab and give permissions to the user role “Admin”.
8 — Create another entity called ProjectExport with the same attributes as the entity that you want to export the data.
9 — Select the Access Rules tab and give permissions to the user roles.
10 — Add an association between ExcelExport and ProjectExport. This association should be 1 to * (one to many)
11 — Double click on the association and select “Delete ‘ProjectExport’ object(s) as well” under “On Delete of ‘ExcelDocument’ object”
Creating the Logic
12 — Create a folder for each entity as such:
13 — Create a microflow called ACT_ProjectExport_ExportList inside the “ProjectExport/Microflows/ACT” folder
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)
15 — Add a decision to check if $MxTemplate is not empty ($MxTemplate != empty)
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”.
17 — Create a new list. As an entity use “ProjectExport” from ExcelExport Module and change the list name to 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”.
19 — Now it is necessary to iterate throughout the list. To do so, add a Loop action and select the list we just retrieved.
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.
21 — After the attribute values, fill the association with the ExcelDocument object.
22 — Add a change list action. Select “ProjectExportList” and use the object we just created as a value.
23 — Outside the loop, drag and drop a commit object action. Select the list called “ProjectExportList”.
24 — Go to microflow properties and give access to the module role “admin”.
25 — Save and go to the App Module -> Marketplace Modules -> XLSReport -> UseMe Folder and Select “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
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.
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
29 — Go to microflow properties and give access to the module role “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.
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.
Configuring the App at runtime
32 — After running the project, click on the Model Reflection page located on the menu.
33 — Select “ExcelExport” and “XLSReport” Modules. Then, “Click to Refresh” in order to synchronize all entities and microflows.
34 — On the menu, click on the Excel Exporter page and Select the New button.
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
36 — Select a date format for the “Date time export format” field
37 — In Worksheets, click new and fill all the fields with the data that you see on the image below.
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.
39 — Create all the columns you need for your 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.
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!