csv文件 内容转义_使用Excel转义CSV文件中的引号和定界符

I try to import a CSV file in Excel, using ; as delimiters, but some columns contains

; and/or quotes.

My problem is : I can use double quotes to ignore the delimiters for a specific string, but if there is a double quote inside the string, it ignores delimiters until the first double quote, but not after.

I don't know if it's clear, it's not that easy to explain.

I will try to explain with a example :

Suppose I have this string this is a;test : I use double quotes around the string, to ignore the delimiter => It works.

Now if this string contains delimiters AND double quotes : my trick doesn't work anymore. For example if I have the string this; is" a;test : My added double quotes around the string ignore delimiters for the first part (the delimiter in the part this; is is correctly ignored, but since there is a double quote after, Excel doesn't ignore the next delimiter in the a;test part.

I tried my best to be as clear as possible, I hope you'll understand what is the problem.

解决方案

When reading in a quoted string in a csv file, Excel will interpret all pairs of double-quotes ("") with single double-quotes(").

so "this; is"" a;test" will be converted to one cell containing this; is" a;test

So replace all double-quotes in your strings with pairs of double quotes.

Excel will reverse this process when exporting as CSV.

Here is some CSV

a,b,c,d,e

"""test1""",""",te"st2,"test,3",test"4,test5

And this is how it looks after importing into Excel:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值