python - 在我的程序中从 xlrd 加载 open_workbook 时遇到问题
问题描述
我真的不知道为什么我在使用 xlrd 的 open_workbook 时总是出错......我的想法是我想创建一个网页来上传一个 excel 文件并通过我的代码打开该文件来处理数据。有没有办法解决这个问题?
def upload(request):
if "GET" == request.method:
messages.warning(request, 'no file uploaded')
return render(request, 'uploadpage/upload.html', {})
else:
excel_file = request.FILES["excel_file"]
wb = xlrd.open_workbook(excel_file)
# iterating over the rows and
# getting value from each cell in row
sheet = wb.sheet_by_name("Summary")
#looping through each rows in a column to find the seller's info
# and storying the values in an array
seller_info = []
count = 1
cfirst, clast = 1,2
while (count < 6):
for colx in range(cfirst, clast):
count = count+1
seller_info.append(sheet.col_values(colx, start_rowx=count-1, end_rowx=count))
return render(request, 'uploadpage/upload.html', {"excel_data": seller_info})
这是前端代码
<div id='upload-container' >
<span>
<h2>Upload Here</h2>
</span>
<div id='input'>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="excel_file">
<div id='btn'>
<button type="submit">Upload File</button>
</div>
</form>
</div>
这是我收到的错误消息
TypeError at / expected str, bytes or os.PathLike object, not InMemoryUploadedFile 请求方法:POST 请求 URL:http: //127.0.0.1 :8000/
Django 版本:2.2.5 异常类型:TypeError 异常值:
预期 str,字节或os.PathLike 对象,而不是 InMemoryUploadedFile
解决方案
推荐阅读
- android - android studio addview is adding the first 2 views normally but then it starts adding them at random location
- python - Python 自动化无聊的东西:Bullet Points 无法运行程序
- r - dbRDA in R, how to with abundance data and missing values for environmental data
- r - R omits repeat values from my excel data
- java - Java Intellij IDE importing builtin classes cannot be resolved
- c# - Using the AWS SDK for .NET, how would we get a list of the filenames from the S3 bucket?
- python - Python:打开带有重音符号的 URL
- node.js - 快递路线 req.app 未定义
- powershell - 从命令行获取 Windows 10 中文件类型关联的最佳方法?
- entity-framework - 使用实体框架生成非多态查询