Convert xlsx file to csv using batch

后端 未结 7 947
醉酒成梦
醉酒成梦 2020-12-01 03:10

How do you convert multiple xlsx files to csv files with a batch script?

7条回答
  •  一向
    一向 (楼主)
    2020-12-01 03:57

    Adding to @marbel's answer (which is a great suggestion!), here's the script that worked for me on Mac OS X El Captain's Terminal, for batch conversion (since that's what the OP asked). I thought it would be trivial to do a for loop but it wasn't! (had to change the extension by string manipulation and it looks like Mac's bash is a bit different also)

    for x in $(ls *.xlsx); do x1=${x%".xlsx"}; in2csv $x > $x1.csv; echo "$x1.csv done."; done
    

    Note:

    1. ${x%”.xlsx”} is bash string manipulation which clips .xlsx from the end of the string.
    2. in2csv creates separate csv files (doesn’t overwrite the xlsx's).
    3. The above won't work if the filenames have white spaces in them. Good to convert white spaces to underscores or something, before running the script.

提交回复
热议问题