The ability that Mendix gives modellers to import excel files into their application is fantastic for a number of reasons – my favourite being that it gives the end user so much more flexibility when it comes to uploading data into the application you’re building.
Here’s how to get a simple excel file imported into your Mendix application using the Mendix Excel Importer Module available for free of the Mendix App Store.
Step 1: Getting Started
Before creating the project it’s important to select, as your language format, USA English or Dutch. The reason is that there is no other language standard to the excel importer so you’ll end up with loads of blank fields which you’ll have to populate yourself (you can, of course, implement your own labels based on the language you chose but to save time it’s best to start with either of those two). The excel importer works using the Reflection module. In order to proceed you’ll need to download both the reflection module as well as the excel importer module. If you download the excel importer first you’ll notice a large number of errors due to the missing reflection module which is automatically resolved upon installation of the reflection module.
Step 2: Fire up that Domain Model
The next step will be to, like all good designs, start with the domain and create a domain model that you’re going to upload the contents of the excel file into, in this case we’ll create a very simple person entity as well as the overview and newEdit file after which we will connect our navigation settings up with the required pages that will implement the excel import module as well as the reflection module — which is needed for synchronizing our objects, allowing the excel importer to access them. Here is a pic of both the domain model I used for the post and the excel file we’re going to upload later.
4 Navigation points need to be established:
Step 3: Sync the Objects
Firstly you’ll need to sync your objects so that the excel importer can get ahold of it so start up the application and navigate to the MxObjects_Overview page and click on the “sync” button. If you run a search your search results should now be populated by your currently instantiated objects.
Step 4: Creating the Upload Template
There are 2 ways to create a template with this module. For this post we’re just going to show how to create one by importing an excel spreadsheet. Now navigate to your Template_Overview page and click on the “New From File”. When using a spreadsheet the application will not be able to interpret xlsx files so you’ll have to be sure that the excel is an xls file. Upload the file and select the relevant sheet index, header row number and first data row number.
Step 5: Now Configure the Template
After you’d uploaded the template page you’ll need to set uploaded columns against the entity you’re planning on uploading the document into and clicked save the application will navigate you to the template page whereby you will be required to complete the template creation process. If you’re stuck with the default USA label, you will have to set the Mendix Object to the entity are uploading, in this case the person entity .
Next you’ll need to “map columns to attributes”. Assign each Column number to an attribute on our domain and only set the unique key to “Yes” on the email attribute. After all the attributes have been set save the template.
Step 6: Import the Data into the Application
Navigate to the Import Files page and create a new import.
Once the import file has been created simply select the uploaded file and click on the import microflow which will complete the import process. You can now navigate to the person overview page and search for the data which you have imported into the application.