How to convert specific sheet to CSV via command line?

Looking at this question and answers (CLI - convert ods to csv with semicolon as delimiter), plus checking some other resources, I found out that you can batch convert spreadsheet files to CSV. This is command you can use:

soffice --headless --convert-to csv:"Text - txt - csv (StarCalc)":"59,ANSI,1" test.ods

Only problem I have is, I don’t want to convert first/default sheet. I want to convert specific sheet (defined by order number or name).
Does anyone know how to convert specific sheet with this command?
My guess is that opening spreadsheet file in specific sheet and then converting would work also, but not sure how to do that via command line.

This worked for me to convert multiple ODS spreadsheet files with multiple sheets to separate CSV files:

Convert ODS to XLSX

libreoffice --headless --convert-to xlsx ./* --outdir ./spreadsheet-xlsx/

Convert XLSX to CSV

cd ./spreadsheet-xlsx/

for i in 2 3 4; do
    for j in $(ls -1 | sed -e 's/\..*$//'); do
 	xlsx2csv -s $i $j.xlsx ../spreadsheet-csv/$j-$i.csv

Just to mention where to obtain xlsx2csv, it is available from GitHub.

Yes, that could work, but since my spreadsheet in quite complex, converting from ods to xlsx would probably destroy something. + it’s longer way :slight_smile:
Anyway, thanks for solution.

This export only first page.

As I came across this again…
LibreOffice 7.2 introduced a --convert-to csv:... parameter to specify which sheet (or all) to export, see LibreOffice 7.2 Community: Release Notes - The Document Foundation Wiki

1 Like