dilshod / xlsx2csv

Convert xslx to csv, it is fast, and works for huge xlsx files
MIT License
1.68k stars 303 forks source link

[Feature Request] Save each sheet as a file instead of combining into one single sheet #218

Open caffeinatedMike opened 3 years ago

caffeinatedMike commented 3 years ago

It would really be useful to have the ability to convert a multi-sheet xlsx file into multiple csv files instead of dumping all the text onto one sheet. Maybe the sheet names can be appended to the outfile name to create orderly filenames?

SirCujo commented 3 years ago

Use -s 0 option Example: xlsx2csv -s 0 excelfile.xlsx /directory/to/write/to/ This accomplishes what you are asking for

caffeinatedMike commented 3 years ago

From what the documentation provides that does not appear to be the behavior. Why else would there be sheet delimiter options? This implies all sheets are combined into a single csv and the rows of data separated via the delimiter per sheet.

SirCujo commented 3 years ago

I just ran it, and thats what it did. Just trying to help you out. I needed the same functionality.

Did you try it, or just dismiss my help?

zhanxw commented 2 years ago

Similar to what @SirCujo mentioned, you can run twice to each sheet. The concept is:

step 1. dump everything

xlsx2csv -a excelfile.xlsx all.csv

step 2. find how many sheet your name and export every one of them

grep -- '--------' all.csv  ## this prints out sheet names
for i in {1..2}; do  xlsx2csv -s $i excelfile.xlsx sheet.$i.csv

Or just use what @SirCuju has mentioned, use -s 0 is the trick to dump all sheets in a output directory.