如何使用逗号(,)导入csv文件 [英] How to import a csv file with a comma(,)

查看:220
本文介绍了如何使用逗号(,)导入csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在导入CSV文件时遇到问题。当地址字段具有多个逗号分隔值时会出现问题,例如家庭没有,街道没有,城镇等



我用谷歌搜索但问题没有解决,因为一个字段包含多个逗号分隔值。



任何想法或解决方案?因为我没有找到任何帮助





例如



我的档案有这些栏目



ID |乐器|单位| EntryDate |评论



2C |笔,螺丝| 1 | 1/1/2010 | rer





我的问题是,仪表栏的值读到这两个列(笔和螺丝)不是(笔,螺丝)。取螺丝作为下一个(单位)列值.....

I am having an issue with importing a CSV file. The problem arises when an address field has multiple comma seperated values e.g. home no, street no, town etc.

I have googled but the problem did not solved because of a single field containing multiple comma separated values.

Any idea or solution? because I didnt found any help


for example

my file have these column

ID |Instrument |Units |EntryDate |Comments

2C | pen,screw |1 |1/1/2010 |rer


my problem is that the value of Instrument column it reads this two column (pen and screw) not(pen,screw) .the take screw as next(Unit) column value.....

推荐答案

文件应该是正确的转义,例如:在Stack Overflow上查看:在CSV文件中处理逗号 [ ^ ]。
The file should be properly escaped, see for instance: "Dealing with commas in a CSV file" at Stack Overflow[^].


你可以清楚地看到,你发布的那行文件不像你说的那样以逗号分隔;它更像是一个管道分隔符;所以将代码中的分隔符更改为管道即。 |而不是逗号,它应该工作正常。让我们知道这是否有效。
You can see clearly, from the line you posted that the file is not comma delimited as you said; it's rather a pipe delimiter; so change the delimiter in your code to pipe ie. "|" instead of a comma "," and it should work fine. Let's know if that does not work out.


这篇关于如何使用逗号(,)导入csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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