rashid.sarwar
rashid.sarwar

Reputation: 59

Running "libreoffice" command through Java to convert file to csv

Please can anyone help me running the following command through java process or process builder.

Process pr = Runtime.getRuntime().exec("libreoffice  --headless ---convert-to csv:\"Text - txt - csv (StarCalc)\":\"09,76,0,1,,0\" --outdir " + f1.getParent()  + " " + fullFileName);

This give me an output of "Unknown command -"

I Used Process builder:

ArrayList<String> cmd = new ArrayList<String>();
        cmd.add("libreoffice");
        cmd.add("--headless");
        cmd.add("--convert-to");
        cmd.add("csv:\"Text - txt - csv (StarCalc)\":09,76,0,1,,0");
        cmd.add("--outdir");
        cmd.add(path);
        cmd.add(fullFileName);

        ProcessBuilder ps = new ProcessBuilder(cmd);
        ps.redirectErrorStream(true);


        Process pr = ps.start();  

It give me error "Unknow parameter csv:\"Text - txt - csv (StarCalc)\":09,76,0,1,,0"

Upvotes: 1

Views: 672

Answers (1)

jferard
jferard

Reputation: 8180

I'm very late but the answer may still be useful to someone. You just have to remove the quotes around Text - txt - csv (StarCalc) :

ProcessBuilder builder = new ProcessBuilder("libreoffice", "--headless",
        "--convert-to", "csv:Text - txt - csv (StarCalc):09,76,0,1,,0",
        "--outdir", path, fullFileName);
builder.redirectErrorStream(true);
Process process = builder.start();

Upvotes: 1

Related Questions