Reputation: 803
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!
Upvotes: 5
Views: 11219
Reputation: 1975
There is a new option now on the CLI:
https://wiki.documentfoundation.org/ReleaseNotes/7.2#Document_Conversion
soffice --convert-to csv:"Text - txt - csv (StarCalc)":44,34,UTF8,1,,0,false,true,false,false,false,-1 sample.ods --outdir data/csv_files
Upvotes: 3
Reputation: 13790
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/.
Upvotes: 2