python 往excel 里面写数据
发布日期:2021-06-30 08:07:28 浏览次数:3 分类:技术文章

本文共 439 字,大约阅读时间需要 1 分钟。

使用的python 的版本为3x

往excel 表格里面写数据使用的是xlwt, 如果电脑上没有 可以使用pip install xlwt 下载一个

步骤如下

1 创建工作薄  xls = xlwt.Workbook()

2 添加工作表 sheet = xls.add_sheet('sample')

3 使用write 写内容

4 使用save保存excel 

具体代码如下

import xlwt# 创建工作薄xls = xlwt.Workbook()# 添加工作表sheet = xls.add_sheet('sample')# 往表格里面写数据sheet.write(0, 0, 'num')sheet.write(0, 1, 'name')sheet.write(1, 0, '1')sheet.write(1, 1, '李白')# 保存excel到指定的目录xls.save(r'C:\Users\Desktop\read\test.xls')

打开excel 效果如下

 

 

 

转载地址:https://huxiaomu.blog.csdn.net/article/details/116152463 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe6 in position 0: ordinal not in range(128)
下一篇:python 读取excel 表格的数据

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月23日 07时18分06秒