将数据插入xlsx
我正在运行一个 python 脚本,它的结果是一组值。假设结果是唯一的日期和时间。
date = now.strftime("%d/%m/%Y")
time = now.strftime("%H:%M:%S")
我想将数据写入 xlsx 文件,但问题是每次脚本完成时数据都会被重写。
我应该如何编写日期以将其添加到 xlsx 中而不是重写它的第一行? 这是我正在使用的代码,我不知道如何更改它。
worksheet.write(1, 0, date)
worksheet.write(1, 1, time)
我希望最终得到的结果应该如下所示:
Date Time
20/03/2022 00:24:36
20/03/2022 00:55:36
21/03/2022 15:24:36
22/03/2022 11:24:36
23/03/2022 22:24:36
I'm running a python script and the result of it is a group of values. Let's say the result is a unique date and time.
date = now.strftime("%d/%m/%Y")
time = now.strftime("%H:%M:%S")
I would like to write down the data into xlsx file, but the problem is that the data is rewrite every single time the scrip is done.
How should I write the date to add it into the xlsx and not to rewrite the first line of it?
That's the code I am using and I'm not sure how to change it.
worksheet.write(1, 0, date)
worksheet.write(1, 1, time)
The result I would like to get at the end should be something like following:
Date Time
20/03/2022 00:24:36
20/03/2022 00:55:36
21/03/2022 15:24:36
22/03/2022 11:24:36
23/03/2022 22:24:36
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以以追加模式打开 Excel,然后继续插入数据。请参考下面的片段:
You can open the excel in append mode and then keep inserting data. Refer below snippet:
最简单的方法是将数据转换为 Pandas 数据框,然后您可以使用以下简单命令轻松将
dataframe
转换为xlxs
文件:The simplest way is to convert your data into a Pandas dataframe, then you can easily convert your
dataframe
intoxlxs
file by using a simple command like: