Crate to convert excel files (xls, xlsx) to csv

Is there any crate to convert an xlsx file to csv?

I tried calamine but the csv produced by calamine is not valid. I generated several csv files from xlsx files using the code provided by calamine in one of there examples but when I try to verify the resultant csv files using different online tools, these files were identified as having some error.

In fact, I was not able to processes through polars

I don't get that. That crate seems to be an XLSX reader, not a CSV writer.

If you are producing a CSV manually from raw text in Excel cells in a naïve manner, that's obviously going to be invalid, because it doesn't escape commas in the text, etc.

The canonical CSV writer in Rust is unsurprisingly enough the csv crate. Use its Writer type to emit valid CSV.

Using calamine, you can read xlsx file and write it to csv. They have given an example code to achieve this on their githut repo here as well.

Actually, I wanted to manipulate some xlsx files using polars. Since polars does not support xlsx files manipulation directly, I will first convert these xlsx file to csv will do necessary manipulation and will than convert the modified csv files back to xlsx files.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.