How to Convert an XSLX File to CSV with UTF-8 Encoding Using LibreOffice / OpenOffice

by Oliver 13. November 2015 21:54

Thanks to this stackoverflow answer I stumbled upon the comment by Aryeh Leib Taurog who shared his solution and a link to the OpenOffice documentation on the available options for the CSV filter.

Here's how to convert the file input.xlsx to the UTF-8 encoded file input.csv in the current directory, with semicolons as field delimiter:

soffice.exe --convert-to "csv:Text - txt - csv (StarCalc):59,,76,1" input.xlsx

On my Windows system the soffice.exe is located under C:\Program Files\LibreOffice 5\program.

Hre's the explanation of the cryptic filter arguments:

  • csv – the extension of the output file
  • Text - txt - csv (StarCalc) – the (ancient) name of the filter (kept for compatibility)
  • 59,,76,1 – these are four arguments:
    • the first parameter is the delimiter in the output file – 59 is the ASCII code for ';'
    • the second parameter is the text delimiter – it's missing because I don't want to wrap text in quotes
    • the third parameter is the file encoding – 76 is the internal OpenOffice code for UTF-8 (from the table on the documentation page)
    • the fourth parameter defines the line number with which to start the export – here, we start with line 1

Thank you, open source community, and happy converting!

PS: For non-windows users, Gnumeric with its command line tool ssconvert might be a good choice for this job, as well.

Comments (2) -

Sarlacii
Sarlacii Mali
6/26/2017 9:07:12 AM #

Thank you... this method worked perfectly with LibreOffice 5.1, where all the other various versions I tried from the 'Net failed with errors. FYI, to use this in Linux, replace "soffice.exe" with "libreoffice5.1 --headless". Works a treat. The xlsx2csv tool from Github also "worked" (as in didn't fail with errors) but it produced a file with tons of extra delimiters (",,,,," etc.)... so was ultimately useless without further editing. Thank you!

Reply

Oliver
Oliver Poland
7/5/2017 1:15:33 PM #

Thanks for sharing, Sarlacii! I'm glad my post helped someone out there Smile

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About Oliver

shades-of-orange.com code blog logo I build web applications using ASP.NET and have a passion for javascript. Enjoy MVC 4 and Orchard CMS, and I do TDD whenever I can. I like clean code. Love to spend time with my wife and our children. My profile on Stack Exchange, a network of free, community-driven Q&A sites

About Anton

shades-of-orange.com code blog logo I'm a software developer at teamaton. I code in C# and work with MVC, Orchard, SpecFlow, Coypu and NHibernate. I enjoy beach volleyball, board games and Coke.