[Basic] Convert ods to csv via commandline

Creating a macro - Writing a Script - Using the API

[Basic] Convert ods to csv via commandline

Postby martinbrait » Tue Mar 14, 2017 2:14 am

Hello guys !

How to convert my ods file, to csv ??? :cry:
I would like to choose the sheets I want to convert to csv.
But nothing of those instructions, worked for me.


"C:\Program Files\LibreOffice 4\program\scalc.exe" --headless -convert-to csv:"Text - txt - csv (StarCalc)":59,34,76,,,,true -outdir converted MySpreadsheet.ods

C:\Program Files\OpenOffice.org 3\program\soffice.exe -headless macro:///MyLibrary.MyModule.MyMacro(arg1, arg2, arg3)

"C:\Program Files\LibreOffice 4\program\soffice.exe" --headless --convert-to xls --outdir "C:\DBA\scripts\CSV-to-Excel" "C:\DBA\scripts\CSV-to-Excel\CSV_file.csv"

help libre office :
https://help.libreoffice.org/Common/Sta ... ameters/vi
https://www.maketecheasier.com/batch-co ... mand-line/


Code: Select all   Expand viewCollapse view
    output as PDF:

    To control, which LibreOffice component generates PDF output, you can use these variants:

    --convert-to pdf:writer_pdf_Export
    --convert-to pdf:calc_pdf_Export
    --convert-to pdf:draw_pdf_Export
    --convert-to pdf:impress_pdf_Export
    --convert-to pdf:writer_web_pdf_Export

    input which is not DOCX:

    To enforce infilters for non-DOCX input formats, you could use (list is not complete):

    --infilter="HTML Document" # for HTML input
    --infilter="MediaWiki" # for MediaWiki input
    --infilter="Text CSV" # for CSV spreadsheet input
    --infilter="Microsoft PowerPoint 2007/2010 XML" # for PPTX input
    --infilter="Microsoft PowerPoint 97/2000/XP" # for PPT input
    --infilter="Windows Metafile" # for WMF input
    --infilter="Enhanced Metafile" # for EMF input
    --infilter="Scalable Vector Graphics" # for SVG input
    --infilter="Microsoft Excel 2007/2010 XML" # for XLSX input
    --infilter="Microsoft Excel 97/2000/XP" # for XLS input
    --infilter="Microsoft Excel 95" # for some XLS input
    --infilter="Microsoft Excel 5.0" # for some XLS input

    output which is not PDF:

    To convert to specific output formats, you could use (list not complete):

    --convert-to html:HTML
    --convert-to html:draw_html_Export # force "Draw" to generate the HTML
    --convert-to mediawiki:MediaWiki_Web # generate MediaWiki output
    --convert-to csv:"Text - txt - csv (StarCalc)" # generate CSV spreadsheet output
    --convert-to pptx:"Impress MS PowerPoint 2007 XML" # generate PPTX
    --convert-to ppt:"MS PowerPoint 97" # generate PPT
    --convert-to wmf:impress_wmf_Export # force "Impress" to generate the WMF
    --convert-to wmf:draw_wmf_Export # force "Draw" to generate the WMF
    --convert-to emf:impress_emf_Export # force "Impress" to generate the EMF
    --convert-to emf:draw_emf_Export # force "Draw" to generate the EMF
    --convert-to svg:impress_svg_Export # force "Impress" to generate the SVG
    --convert-to svg:draw_svg_Export # force "Draw" to generate the SVG
    --convert-to xlsx:"Calc MS Excel 2007 XML" # generate XLSX
    --convert-to xls:"MS Excel 97" # generate XLS like Excel 97
    --convert-to xls:"MS Excel 95" # generate XLS like Excel 95
    --convert-to xls:"MS Excel 5.0/95" # generate XLS like Excel 5.0/95




'What's about this, to convert multiple ODS spreadsheet files with multiple sheets to separate CSV files ?
Code: Select all   Expand viewCollapse view
    '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
    done
    done


extrait de : https://ask.libreoffice.org/en/question ... mand-line/


'Auteur : Mikeyy

How to mass export certain sheet to CSV?

Postby Mikeyy » Mon Feb 23, 2015 3:28 pm
Since I'm not programmer and making macros is out of my league, I fixed this easier way. :)

1. I made a batch ".bat" file for windows.

Code: Select all Expand view
for /f "delims=|" %%f in ('dir /b .\ODSDIRECTORY') do "C:\Program Files (x86)\LibreOffice 4\program\soffice.exe" --headless --convert-to csv:"Text - txt - csv (StarCalc)":"59,ANSI,1" --outdir .\CSV ".\ODSDIRECTORY\%%f"
exit



What it does is next:
- searches all files in directory
- for every file in directory it executes command after "do"
- "delims=|" takes into account files with spaces in name, but files with brackets will not pass, and probably also files with other strange characters
- "C:\Program Files (x86)\LibreOffice 4\program\soffice.exe" is path name to LO or AOO, if it's not global command
--convert-to csv:"Text - txt - csv (StarCalc)":"59,ANSI,1" for this part thanks to rudolfo, without him it wouldn't be possible
--outdir .\CSV this is only if you want to have output directory different then directory where your command is executed
- ".\ODSDIRECTORY\%%f" this points to files which will be converted, if you remove "" filenames with spaces in them will fail

2. I merge all CSV into one CSV:

Code: Select all Expand view
copy .\CSV\*.csv merged.csv



After that, you can edit it however you like it.
Since I didn't find a way to export 2nd, 3rd, 4th... sheet, you must have that sheet as 1st in your document.





Useful hyperlinks :
https://ask.libreoffice.org/en/question ... mand-line/
https://forum.openoffice.org/en/forum/v ... 20&t=87890
https://wiki.openoffice.org/wiki/Docume ... er_Options
https://ask.libreoffice.org/en/question ... ds-quoted/

Shall I use "unoconv" ?


Could you help me, please ?

Thank you very much. Goodbye !
LibreOffice 3.6.2 on Windows7
martinbrait
 
Posts: 5
Joined: Fri Apr 26, 2013 9:15 am

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 6 guests