在CSV导出不同的解决方案进行处理零 [英] Different Solution for handling zero in CSV Exporting

查看:110
本文介绍了在CSV导出不同的解决方案进行处理零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

导出荫DATAS我为.csv从asp.net项目格式。当IAM出口在开始时拥有零这些数字中加入处理

Iam Exporting my datas to .csv format from asp.net project. When iam exporting those numbers having zero at beginning was handled by adding

="0183"

然后,它是在Excel 0183中可见。
但问题是,当我复制这些东西,它再次复制其他文件=0183

Then it is visible as 0183 in excel. But the problem is when i am copying these things to other files it again copied as ="0183"

所以,任何人都可以帮我办理零出口数量开始从C#代码为.csv?

So , can anyone help me to handle zero started numbers in export to .csv from C# coding?

推荐答案

的问题是,它的Excel的自动多数民众赞成在CSV转换为字符串。如果你创建一个简单的CSV和使用Open用Excel在Excel中打开它,你可以看到的行为。所以,第一和更容易的选择将使得列类型文本和观看它。

The problem is that its the excel thats auto converting the csv to string. If you create a simple CSV and open it in excel using the Open with Excel you can see the behavior. So first and easier option will be making the column type text and viewing it.

另一种选择将是它重新转换为另一种格式像在此之前使用正则表达式来解析列。

The other option will be to parse the column using regex before re-translating it to another format like this.

var inputString = "=\"0813\"";
var match = Regex.Match(inputString, "=\"([^\"]*)\"");
var output = match.Groups.Count > 1 ? match.Groups[1].Value : inputString;

这篇关于在CSV导出不同的解决方案进行处理零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆