如何存储使用 pyExcelerator 创建的 excel 文件作为 db.BlobProperty() 的输入
如何存储使用 pyExcelerator 创建的 excel 文件作为 db.BlobProperty() 的输入?
实际上我需要的是使用taskqueue程序将创建一个excel文件并将其存储在数据存储中。并将向用户发送下载该文件的链接。我该怎么做?请帮助我
数据模型:
class filestore(db.Model):
stock_file = db.BlobProperty()
用于将 Excel 文件存储在数据存储中的 Python 代码
from pyExcelerator import *
class MainHandler(webapp.RequestHandler):
def get(self):
w = Workbook()
ws = w.add_sheet('Hey, Dude')
ws.write(0, 0, 'Part Number')
self.response.headers['Content-Type'] = 'application/ms-excel'
self.response.headers['Content-Transfer-Encoding'] = 'Binary'
self.response.headers['Content-disposition'] = 'attachment; filename="Test.xls"'
temp_file = filestore()
temp_file.stock_file = db.blob(wb.save(self.response.out)) // Storing 0kb file
temp_file.put()
插入新文件后,文件大小为 0kb 为什么?
How can i store excel file created using pyExcelerator as input for db.BlobProperty() ?
Actally what i need is that Using taskqueue program will create a excel file and store it in the datastore. And will send a link to the users to download the file. How do i do this ? Please help me
Datamodel:
class filestore(db.Model):
stock_file = db.BlobProperty()
Python code for storing the excel file in datastore
from pyExcelerator import *
class MainHandler(webapp.RequestHandler):
def get(self):
w = Workbook()
ws = w.add_sheet('Hey, Dude')
ws.write(0, 0, 'Part Number')
self.response.headers['Content-Type'] = 'application/ms-excel'
self.response.headers['Content-Transfer-Encoding'] = 'Binary'
self.response.headers['Content-disposition'] = 'attachment; filename="Test.xls"'
temp_file = filestore()
temp_file.stock_file = db.blob(wb.save(self.response.out)) // Storing 0kb file
temp_file.put()
After inserting new file, file size in 0kb why ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的目标是创建 Excel 文件并将其保存为 blob 供以后使用,则需要首先将其保存为 StringIO 对象,而不是像您当前所做的那样构造响应。
以下是使用 xlwt(pyExcelerator 的一个分支)的示例:
If your goal is to create an Excel file and save it as a blob for later use you need to first save it as a StringIO object, not construct a response, as you are doing currently.
Here is a sample using xlwt (a fork of pyExcelerator):
此代码会将文件保存为数据存储中的 blobproperty()。
This code will save the file as blobproperty() in datastore.