Search code examples
.netvb.netcsvcsvhelper

How to keep the leading zeros in CsvHelper CsvWriter?


I am using the CsvHelper library to read/write csv files from my .net code.

All functionality are working fine so far, yet I am stuck in how can I keep the leading zeros when writing to csv file using the CsvWriter Class? Currently, the string values such as "020" or "001" get printed on the csv file as "20" and "1"


Solution

  • This is a known problem, with a known solution, described here:

    The solution is to write a number in this format:

    ="001"
    

    These don't work (tested in 2010) - leading zeros are trimmed: 001, "001", =001