C# Use Response to export Excel cell format and set it to text format
C# Use Response to export Excel cell format and set it to text format
System: Win10
IDE: Visual Studio 2019
.NET CLR version: 2.0.50727
Problem Description
Recently, when using C# Response to export Excel data, when it is found that the exported fields are all numbers and are too long (such as bank account numbers), they will be automatically converted to scientific notation, as shown below
Solution
To solve this method, you only need to set the output format of the field to text. According to this idea, we add a style to the field. vnd.ms-excel happens to have a number-to-text method: vnd.ms-excel.numberformat:@
sb.Append("<td style=\"vnd.ms-excel.numberformat:@\" >" + dataTable.Rows[i]["fyfksp_Account"] + "</td>");