How to Export Excel File/Report with Excel Exporter - Mendix 10
Tags: mendix, webdev, programming, lowcode
Published: 2023-08-15 14:09:33

{% youtube cHMRqaKcicI %}
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b1jwihsdz4wxgvvey942.png)


## Step by Step
1 - Download the module Excel Exporter from the marketplace.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6x70n4qbvp8ekn54en71.png)


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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/471fckc1yu4jgqfgllxi.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t5ysy7mrbz98bigzsbq0.png)


3 - Create a new project module called ExcelExport


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q5ml85x97rbde5iwdhgz.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jpt5xb6g995vmvbdid68.png)


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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c6bi2wjoq2hmsj28upck.png)


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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqv1slx20m3ej2wghj8o.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rv6mckehkplok8tqnhpe.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pxafei2u8ld0d8691b0n.png)


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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxifffv4llv0t0c8utik.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rf1ql2dp76npznkehmuo.png)


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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ui49nyn58500ech76dh.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nl9b9g3eo6ho6q1ccgcj.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fnw8u3hqtaui1qwdc0bd.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l5s9p0yamyavn3qq5ujk.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gp5kyl40relqegwqwcwe.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dce95r98tqmpidqexqit.png)

12 -  Create a folder to each entity as such:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hw468xpscew1s38bz5lf.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uejtz4mzkfkbjgadsp74.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6lq8y6y4vftfpxjqv65b.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8xb8vgid9ljs5g1k0n63.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1snivs08n6shn1eryyr9.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4hit4be2ce0l8cbk0cep.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0tggde7qv9bhbhz7wqcj.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hyv9b4joqri6goynarke.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v1vgu2ph66blx5vwmax4.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/po4fmiycif32h081ow47.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ov7lpsql5rrsnjhvetzi.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xlxypfi10251fw27oi4k.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kugsf7vi643ybkineuck.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x2jmtxqtnajuy6hiac4m.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pojat23nq1dmq8gpmvel.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1h530yw8vldt6ywaicpr.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h02xfnet0fvk9strzl2o.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4w7wwp131341jwytogbi.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hcawcqu8qpgsen9hyq5h.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abe0pbvmfqfbs2bzsi11.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v43ep7yljqry114fpdit.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5mdy56tc8da2y4azj5j6.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yvu6ic0xkhspwkjqb3m1.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8n2ryyl1izrtgsebtxln.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/byx0mcl19p0gawgeukyg.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xrb19tt2y34dmqnaghqm.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jzf4tkh886xacl9xm43j.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/50z9jzb2clckxsgeyb03.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqt9de1pb81xtfmon0rd.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wl1e1io2iljojsw3cngt.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fi6lyzk131xud33y8i1y.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1bnysrc4vgg7lw3hb4fr.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgorckapy90j6f0182j6.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dld2yyaq2o7hexx4ro3c.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5m1veehjmsq430s2nsf2.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0xjmgtl8cynb6bjrbonn.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y44y4sfyun9upe0s98np.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x9epjhnjbc67j37aceke.png)

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](https://mendixwithme.medium.com/). For great videos, you can visit our [Youtube page](https://www.youtube.com/channel/UCtRcKyh_4dvK-uCBtnbUWFw).
Are you interested in getting more involved with our community? Join us in our [Discord Community Channel](https://discord.gg/YHre8dXz3q).