dashbitco / nimble_csv

A simple and fast CSV parsing and dumping library for Elixir
https://hexdocs.pm/nimble_csv
767 stars 51 forks source link

Escape only strings with leading zeros #62

Closed patatoid closed 3 years ago

patatoid commented 3 years ago

Hi,

Wanted to generate a CSV file where common spreadsheet tools interpret strings like "001" as strings, not numbers. One way to do that is to escape that cell. Tried to add 0 as reserved characters do not meet my needs as I don't want to escape other cells with 0 which are numbers.

Do you think there is a way to achieve the escaping of cells with leading zeros ?

josevalim commented 3 years ago

You will have to transform the data before dumping it to NimbleCSV - as we simply encode the data as is. So for example, convert the numbers explicitly to strings or escape them with additional zeros yourself. :)