How can I apply CSV rule in my CSV file generated?

0
Hello there! I have been working on a project where user data gets downloaded in the form of a CSV file, including fields like Username, Email ID, Address, etc. The data I am receiving is correct, but I want to apply some CSV rules to the file, such as: The report CSV files should use commas as delimiters. The report CSV files should use double-quote marks to delimit field values that contain spaces. If a field value contains double quotes, the double quotes should be doubled up so the parser can differentiate them. I would be really grateful for the help.
asked
2 answers
2

Hi Tushar,

 

Which module are you using to export to csv? I'm not sure if the standard button in Mendix or the Excel exporter give this kind of freedom in terms of setting up the export. I do know the CSV module does offer these settings. The first two you can edit inside the microflow action and the last one you can use custom logic when writing the CSV.

 

image.png

 

https://marketplace.mendix.com/link/component/108605

answered
1

Hi Tushar,

 

Within the microflow you use to write the entity's to the CSV, you can add custom logic. See the screenshot below, we first retrieve the Persons we want to export, then for every person we create a nonpersistable object. In the function all double quotes are replaced and doubled up, and the whole string is being quoted as well. Then we write the entity to the CSV file and delete it to clear up memory. 

 

https://docs.mendix.com/refguide/string-function-calls/#12-replaceall

'"'+replaceAll($IteratorExamplePerson/Name,'"','""')+'"'

 

image.png

answered