Python中使用第三方库xlrd来写入Excel文件示例
作者:junjie 时间:2023-08-16 21:37:29
继上一篇文章使用xlrd来读Excel之后,这一篇文章就来介绍下,如何来写Excel,写Excel我们需要使用第三方库xlwt,和xlrd一样,xlrd表示read xls,xlwt表示write xls,同样目前版本只支持97-03版本的Excel。xlwt下载:xlwt 0.7.4
安装xlwt
安装方式一样是python setup.py install就可以了,或者直接解压到你的工程目录中。
API介绍
获取一个xls实例
xls = ExcelWrite.Workbook()
添加一个sheet
sheet = xls.add_sheet("Sheet1")
向sheet中写入数据
sheet.write(row_index, col_index, value)
保存生成xls
xls.save(file_name)
使用xlwt
# -*- coding: utf-8 -*-
'''
Created on 2012-12-14
@author: walfred
@module: XLRDPkg.write
@description:
'''
import xlwt as ExcelWrite
def writeXLS(file_name):
value = [["name", "jim", "hmm", "lilei"], ["sex", "man", "woman", "man"], ["age", 19, 24, 24], ["country", "USA", "CHN", "CHN"]]
xls = ExcelWrite.Workbook()
sheet = xls.add_sheet("Sheet1")
for i in range(0, 4):
for j in range(0, len(value)):
sheet.write(j, i, value[i][j])
xls.save(file_name)
if __name__ == "__main__":
writeXLS("./test_write.xls");
当然这只是简单的介绍下如何使用xlwt,更多功能个API需要读者自行从下载包中学习,比如设置格式、超链接、公式等。
标签:Python,xlrd,写入,Excel文件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
MySQL提示:The server quit without updating PID file问题的解决办法
2024-01-14 21:36:05
培养色感的一些经验分享
2013-11-10 03:47:03
![](https://img.aspxhome.com/file/UploadPic/20071/200713110530379s.gif)
pytorch 自定义卷积核进行卷积操作方式
2021-07-24 22:54:39
![](https://img.aspxhome.com/file/2023/6/92136_0s.jpg)
PHP中把stdClass Object转array的几个方法
2023-11-19 06:56:33
让Django支持Sql Server作后端数据库的方法
2024-01-25 13:58:56
Python下使用Psyco模块优化运行速度
2022-08-13 13:01:09
python实现人机对战的井字棋游戏
2023-02-11 15:37:45
![](https://img.aspxhome.com/file/2023/3/133753_0s.jpg)
忘记ftp密码使用python ftplib库暴力破解密码的方法示例
2021-01-02 03:08:31
对python抓取需要登录网站数据的方法详解
2023-01-18 04:58:41
jquery效率探索
2008-01-08 18:06:00
asp中常用的字符串安全处理函数集合(过滤特殊字符等)
2011-02-20 10:40:00
PJBlog3优化——单击自动输入验证码
2009-05-17 11:03:00
nginx+uwsgi+django环境搭建的方法步骤
2022-01-12 16:34:59
Autopep8的使用(python自动编排工具)
2022-07-04 11:10:47
![](https://img.aspxhome.com/file/2023/7/96967_0s.png)
Golang在Mac、Linux、Windows下如何交叉编译的实现
2024-02-23 06:00:02
Python特效之数字成像方法详解
2022-09-12 13:16:22
![](https://img.aspxhome.com/file/2023/2/90782_0s.jpg)
Python实战之外星人入侵游戏示例代码
2023-12-23 08:18:18
![](https://img.aspxhome.com/file/2023/4/109954_0s.jpg)
vue+vux实现移动端文件上传样式
2024-05-02 16:34:40
![](https://img.aspxhome.com/file/2023/2/130232_0s.png)
Python3如何使用tabulate打印数据
2021-04-17 15:09:26
![](https://img.aspxhome.com/file/2023/7/124137_0s.png)
python实现FTP服务器服务的方法
2021-01-08 10:07:38
![](https://img.aspxhome.com/file/2023/1/72001_0s.png)