This example is based on the Java and JavaServer Faces (JSF) with PrimeFaces component library tech stack, but it can also be used with other frameworks.
A problem description.
There are some cases with table data exporting when exported tables contain unexpected values. Or the values need to be updated under certain conditions. Or if we need extra columns/data to combine different UI views in one exported table. There are few examples below.
Primefaces dataExporter is used to export data. A standard configuration looks like

and it gives us a table which was configured accordingly

Let’s export the data (by clicking the XLSX icon at the top right corner) and see what is in the exported file.


As we can see there is the first column, which is a checkbox mark in the UI table, is shown like a Java object with text ‘javax.faces.component.UIPanel@3e45c1ea‘. Let’s consider it the first thing to customize in the exported file. Probably, we want to see it like ‘Selected’ in the header.
Also, there is the last column, which is a button in the UI table, is just empty string (“”) in the header. We don’t need it in the file at all. Let’s consider it the second thing to customize in the exported file.
Now let’s check values in the exported file.
The first column’s value is “false” (or “true” when it’s selected in the UI table). It’s not a very ‘user-friendly’ message, somebody would like to see it like “Selected” or “Unselected”. It would be the third thing to customize in the exported file.
The ‘Status’ column and the right column with the blue button also have unreadable messages. These values are text versions of Java objects, and additionally hower text for those columns accordingly. Even if we needed an explanation of the column values we would want them to be present in a more readable format. In this case, we just remove the extra text and update the values.
So, that is what the problem is, and below is a solution.
A solution.
To customize the exported file we should catch it before downloading and update it. We use Primefaces attribute ‘postProcessor‘.

Then we update the file in Java code so it will be customized before downloading. Let’s see the code itself.


The updated exported file:

As we can see the values had been updated and the updated file was downloaded.
The same approach can be used to add more columns (values) to xlsx files or other file types where text values need to be updated.
If you need help with solutions for data analysis and/or any solutions for data management, please contact me sergiitechinfo@gmail.com