I want to export the result of a query to xlsx file format.
I know we can export it to csv file, but I want to export it to xlsx file.
Like the following:
copy(select name_related from hr_employee limit 3) to '/tmp/ABC.xlsx'
delimiter ',' xlsx header;
Best Answer
PostgreSQL can't do this natively, but you can convert the CSV output to an XLSX file with a simple perl script.
csv2xlsx
:For this script to work, install
Excel::Writer::XLSX
andText::CSV
perl modules, either through apt-get/yum, or throughsudo perl -MCPAN -e 'install Excel::Writer::XLSX'
andsudo perl -MCPAN -e 'install Text::CSV'
.Usage example: