CSV Exporting: Preserving leading zeros

前端 未结 4 565
后悔当初
后悔当初 2020-12-21 21:25

I\'m working on a .NET application which exports CSV files to open in Excel and I\'m having a problem with preserving leading zeros when the file is opened in Excel. I\'ve

4条回答
  •  [愿得一人]
    2020-12-21 22:12

    As @GSerg mentions, this is not a CSV issue.

    If your users must edit/save in Excel they need to select the entire worksheet, right-click and choose "Format Cells" and from the Category list select "Text" after opening the csv file. This will preserve the leading zeros since the numbers will be treated as simple text.

    Alternatively, you could use Open XML SDK 2.0, or some other Excel library, to create an xlsx file from your csv data and programmaticaly set the Cell type to Text in order to take the end users out of the equation...

提交回复
热议问题