如何与XLSXWriter一起工作而无需将文件保存在磁盘中
我希望能够从我拥有的一些数据中创建一个Excel文件。准备就绪后,我想使用Python Telegram机器人发送它并乘坐文件。
理想情况下,将从划痕创建文件并将其保存到一个变量中,一旦使用Python Telegram Bot模块发送了文件,以发送文件并结束文件而无需将文件保存到磁盘中。
import xlsxWriter as xs
workbook = xs.Workbook('demo.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'Hello')
workbook.close()
好的,所以在写入命令之后,我看不到文件夹中创建的任何文件,但是我不知道该文件是否在那里等待关闭而不是不存在。
hoy我可以不保存而做到吗
bot.send_file(my_xlsx,chat_id=1111111)
I want to be able to create an excel file from some data I have. Once it is ready, I want to send it using a python telegram bot and get ride of the file.
Ideally, the file will be created from scratch and saved into a variable, and once it is done sent using the python telegram bot module to send the file and end it without saving the file to the disk.
import xlsxWriter as xs
workbook = xs.Workbook('demo.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'Hello')
workbook.close()
Ok so after the write command I don't see any file created in the folder, but I don't know if the file is there waiting to be closed instead of not existing.
Hoy can I, without saving it, do
bot.send_file(my_xlsx,chat_id=1111111)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不将文件保存在磁盘中的一种方法是将其写入字节对象。 Bytesio是一个缓冲区,因此Excel信息存储在内存中:
您可以使用方法
getValue()
。有关字节的更多信息(和io
一般):One way to not save the file in disk is writing it in a BytesIO object. BytesIO is a buffer, so the excel information is stored in memory:
You can get the data stored using the method
getvalue()
. More info about BytesIO (andio
library in general) here: