excel对csv的转义

最近遇到一个问题,csv里数字过长会被excel转义为科学计数法显示(经过试验,超过8位就会被转)。在网上搜索到别人的经验,得知可以在前面加\t来禁止excel对csv转义。

PS:如果要禁止excel对excel的转义,可以在内容前加上半角单引号'。 

原文链接:http://www.zu14.cn/2009/05/07/csharp-export-data-to-csv-xls-avoid-number-auto-transfering/ 

附上自己的转义方法:

 private string ExcelEscape(string cell)

        {
            if (string.IsNullOrEmpty(cell))
            {
                return cell;
            }
                        
            if (cell.Contains(','))
            {
                cell = "\"" + cell + "\"";
            }            

            if (cell.StartsWith("0") || cell.Length > 8)
            {
                cell = "\t" + cell;
            }

            return cell;
        }
原文地址:https://www.cnblogs.com/rusteel/p/2217481.html