Home » excel » linux – libreoffice convert all/specific sheet(s) from excel to csv

linux – libreoffice convert all/specific sheet(s) from excel to csv

Posted by: admin May 11, 2020 Leave a comment

Questions:

How do I convert to CSV anything else than the first sheet of an excel file to CSV?

My current code is :

libreoffice --headless --convert-to csv --outdir data/csv_files  data/excel_files/*.*

I would like to convert the n-th sheet, or even all sheets, not only the first one.

Thx!

How to&Answers:

When saving as CSV, LibreOffice will only save the active sheet. The command
libreoffice --convert-to will use the first sheet.

Instead of using --convert-to, this is a relatively simple task with macros. The macro just needs to activate a particular sheet and then save as CSV. If you write a macro called “MyMacro1” that takes the name of a sheet, it can be run from the command line like this:

soffice macro:///Standard.Module1.MyMacro1("sheet 2")

Some example code is here. Also keep Andrew Pitonyak’s Macro document handy as a reference.

Alternatively, here is a solution using xslx2csv, which I have not tried: https://ask.libreoffice.org/en/question/46466/how-to-convert-specific-sheet-to-csv-via-command-line/.