{"id":100,"date":"2025-02-24T17:36:50","date_gmt":"2025-02-24T17:36:50","guid":{"rendered":"https:\/\/infotechville.com\/blog\/?p=100"},"modified":"2025-02-24T17:36:51","modified_gmt":"2025-02-24T17:36:51","slug":"how-to-customize-exported-data-in-xlsx-file","status":"publish","type":"post","link":"https:\/\/infotechville.com\/blog\/index.php\/2025\/02\/24\/how-to-customize-exported-data-in-xlsx-file\/","title":{"rendered":"How to customize exported data in XLSX file."},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p><strong>A problem description.<\/strong><\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Primefaces dataExporter is used to export data. A standard configuration looks like<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"172\" src=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-11-1024x172.png\" alt=\"\" class=\"wp-image-101\" srcset=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-11-1024x172.png 1024w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-11-300x50.png 300w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-11-768x129.png 768w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-11.png 1195w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>and it gives us a table which was configured accordingly<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"187\" src=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-12-1024x187.png\" alt=\"\" class=\"wp-image-102\" srcset=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-12-1024x187.png 1024w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-12-300x55.png 300w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-12-768x140.png 768w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-12.png 1536w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Let\u2019s export the data (by clicking the XLSX icon at the top right corner) and see what is in the exported file.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"136\" src=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-13-1024x136.png\" alt=\"\" class=\"wp-image-106\" srcset=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-13-1024x136.png 1024w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-13-300x40.png 300w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-13-768x102.png 768w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-13.png 1441w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"99\" src=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-14-1024x99.png\" alt=\"\" class=\"wp-image-107\" srcset=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-14-1024x99.png 1024w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-14-300x29.png 300w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-14-768x74.png 768w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-14-1536x149.png 1536w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-14.png 1878w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>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 \u2018<em>javax.faces.component.UIPanel@3e45c1ea<\/em>\u2018. Let\u2019s consider it the first thing to customize in the exported file. Probably, we want to see it like \u2018Selected\u2019 in the header.<\/p>\n\n\n\n<p>Also, there is the last column, which is a button in the UI table, is just empty string (\u201c\u201d) in the header. We don\u2019t need it in the file at all. Let\u2019s consider it the second thing to customize in the exported file.<\/p>\n\n\n\n<p>Now let\u2019s check values in the exported file.<\/p>\n\n\n\n<p>The first column\u2019s value is \u201cfalse\u201d (or \u201ctrue\u201d when it\u2019s selected in the UI table). It\u2019s not a very \u2018user-friendly\u2019 message, somebody would like to see it like \u201cSelected\u201d or \u201cUnselected\u201d. It would be the third thing to customize in the exported file.<\/p>\n\n\n\n<p>The \u2018Status\u2019 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.<\/p>\n\n\n\n<p>So, that is what the problem is, and below is a solution.<\/p>\n\n\n\n<p><strong>A solution.<\/strong><\/p>\n\n\n\n<p>To customize the exported file we should catch it before downloading and update it. We use Primefaces attribute \u2018<em><mark>postProcessor<\/mark><\/em>\u2018.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"208\" src=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-16-1024x208.png\" alt=\"\" class=\"wp-image-111\" srcset=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-16-1024x208.png 1024w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-16-300x61.png 300w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-16-768x156.png 768w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-16.png 1193w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Then we update the file in Java code so it will be customized before downloading. Let\u2019s see the code itself.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"906\" height=\"872\" src=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-17.png\" alt=\"\" class=\"wp-image-113\" srcset=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-17.png 906w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-17-300x289.png 300w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-17-768x739.png 768w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"933\" height=\"495\" src=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-19.png\" alt=\"\" class=\"wp-image-115\" srcset=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-19.png 933w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-19-300x159.png 300w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-19-768x407.png 768w\" sizes=\"auto, (max-width: 933px) 100vw, 933px\" \/><\/figure>\n\n\n\n<p>The updated exported file:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"120\" src=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-20-1024x120.png\" alt=\"\" class=\"wp-image-117\" srcset=\"https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-20-1024x120.png 1024w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-20-300x35.png 300w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-20-768x90.png 768w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-20-1536x180.png 1536w, https:\/\/infotechville.com\/blog\/wp-content\/uploads\/2025\/02\/image-20.png 1902w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>As we can see the values had been updated and the updated file was downloaded.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>If you need help with solutions for data analysis and\/or any solutions for data management, please contact me&nbsp;<a href=\"mailto:sergiitechinfo@gmail.com\">sergiitechinfo@gmail.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/infotechville.com\/blog\/index.php\/2025\/02\/24\/how-to-customize-exported-data-in-xlsx-file\/\">Read more<span class=\"screen-reader-text\">How to customize exported data in XLSX file.<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-java-programming","entry"],"_links":{"self":[{"href":"https:\/\/infotechville.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/infotechville.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/infotechville.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/infotechville.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/infotechville.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=100"}],"version-history":[{"count":8,"href":"https:\/\/infotechville.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/100\/revisions"}],"predecessor-version":[{"id":118,"href":"https:\/\/infotechville.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/100\/revisions\/118"}],"wp:attachment":[{"href":"https:\/\/infotechville.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/infotechville.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/infotechville.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}