在Django中读取Excel生成的CSV文件时出错

时间:2021-05-14 10:07:46

I have problems reading a CSV file generated by Excel. The code reading the file is very simple and it works ok with CSV files generated by hand:

我在阅读Excel生成的CSV文件时遇到问题。读取文件的代码非常简单,并且可以正常生成的CSV文件:

file = request.FILES['organisations']
data = csv.reader(file, dialect='excel', delimiter=',', quotechar='"')

for line in data :
    ...

However, I get the following error pointing to that last line when I try to upload an Excel CSV file:

但是,当我尝试上载Excel CSV文件时,我收到以下指向最后一行的错误:

new-line character seen in unquoted field - do you need to open the file in universal-newline mode?

在未引用字段中看到的换行符 - 您是否需要以通用换行模式打开文件?

I've been Googling around but haven't been able to find something useful. Any help is appreciated!

我一直在谷歌搜索,但一直没有找到有用的东西。任何帮助表示赞赏!

1 个解决方案

#1


0  

Update this line:

更新此行:

data = csv.reader(StringIO.StringIO(file.read()), dialect='excel', delimiter=',', quotechar='"')

#1


0  

Update this line:

更新此行:

data = csv.reader(StringIO.StringIO(file.read()), dialect='excel', delimiter=',', quotechar='"')