Elevate Your Reporting Game: Dynamic Excel Reports with OQL Queries in Mendix (Banner Image)
Elevate Your Reporting Game: Dynamic Excel Reports with OQL Queries in Mendix

Elevate Your Reporting Game: Dynamic Excel Reports with OQL Queries in Mendix

Rishabh Shandilya
Mendix Community
Published in
4 min readMay 7, 2024

--

Leveraging OQL Queries for Dynamic Data Retrieval

OQL queries are the backbone for retrieving data from the database in Mendix. With the enhanced Export OQL to Excel Java action, you can pass OQL queries as parameters, allowing for dynamic data retrieval tailored to your specific requirements.

Code:

//Pass OQL query as a parameter
private final java.lang.String statement;

Utilizing Excel Writer for Enhanced Visualization

In contrast to the CSV writer used in Export OQL to CSV Java action, we now utilize Excel Writer to create header columns and rows in Excel sheets. This enhances your Excel reports' visual appeal and usability, ensuring they make a lasting impression.

Code:

//Utilizing Excel Writer for enhanced visualization
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Output");

Seamlessly Populating Data Cells

For each row of data retrieved from the database, cells are created below the header row to push the data into the Excel sheet. This ensures that your Excel reports accurately reflect the database records, maintaining data integrity throughout the process.

Code:

//Populating data cells in Excel sheet
for (IDataRow row : results.getRows()) {
Row excelRow = sheet.createRow(++rowCount);
for (int i = 0; i < tableSchema.getColumnCount(); i++) {
Object value = row.getValue(getContext(), i);
PushValueInCell(i, dateCellStyle, numberStyle, intStyle, excelRow, value);
}
}

Simplifying File Management with IMendix Object

Finally, the generated Excel file is encapsulated within an IMendix object, simplifying file management and retrieval. This ensures seamless integration with existing workflows and enhances the overall user experience.

Code:

//Storing Excel file in IMendix object
IMendixObject result = Core.instantiate(getContext(), this.returnType);
result.setValue(getContext(), FileDocument.MemberNames.Name.toString(), tmpFile.getName());

Integrating the Java action into your Mendix workflow

Once you’ve enhanced the Export OQL to Excel Java action, the next step is integrating it into your Mendix workflow. Here’s how you can do it:

Create a Microflow:
Start by creating a microflow in Mendix where you’ll utilize the enhanced Java action. This microflow will orchestrate the process of generating the Excel file and downloading it.

Add the enhanced Java Action:
In the microflow, add the enhanced Export OQL to Excel Java action as a step. Pass the necessary parameters, including the OQL query, to customize the report generation process according to your requirements.

Invoke “Download File” activity: After generating the Excel file add another activity named “Download File” to the microflow. This activity is readily available in the Mendix platform and simplifies the process of downloading files for end-users.
Configure Download File activity: Configure the Download file activity to specify the Excel file generated by the Java action as the file to be downloaded.

Conclusion

The enhanced Export OQL to Excel Java action in Mendix empowers organizations to craft dynamic and insightful Excel reports effortlessly. From streamlined data retrieval to enhanced visualization, the possibilities are endless. Join us in embracing excellence in Excel reporting and unlocking the full potential of the Mendix platform.

Are you ready to elevate your reporting experience with Mendix? Contact Resilient IT Services today to learn more about how our platform can transform your business. Let’s embark on a journey of data-driven excellence together.

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!

--

--