When you are exporting a DataRow value using a Stream Writer to formats like CSV, we write as dr[counter].ToString(). If this value starts with zero, Excel removes the leading zeroes (unless the column is formatted as text).
In order to fix this, we would need to manually write that as the following.
if(dr[i].ToString().StartsWith("0")) { sw.Write(@"="""+dr[i]+@""""); } else { sw.Write(dr[i].ToString()); }
Related Articles
- Converting JSON Results in Camel Case
- Encrypt a Config Section Using .NET
- Change Default Assembly Output Path in .NET
Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.






















