python list格式数据excel导出方法
作者:大白先生的微博 时间:2023-09-19 14:21:01
如下所示:
# _*_ coding:utf-8 _*_
#-----------------------------------------------
# import modules
#-----------------------------------------------
import os
import xlwt
import sys
import types
def set_style(name, height, bold = False):
style = xlwt.XFStyle() #初始化样式
font = xlwt.Font() #为样式创建字体
font.name = name
font.bold = bold
font.color_index = 4
font.height = height
style.font = font
return style
def write_excel():
#创建工作簿
workbook = xlwt.Workbook(encoding='utf-8')
#创建sheet
data_sheet = workbook.add_sheet('demo')
#列表格式数据
excelData = [
['tdate', u'交易所', u'股票代码'],
[20170103, 'CNSESZ', '300319'],
[20170104, 'CNSESZ', '300367'],
[20170104, 'CNSESZ', '300367']
]
#定义循环下标
index = 0
for i in excelData:
#每一列的内容(i)
for x, item inenumerate(i):
#下标(x),单元元素(item)
data_sheet.write(index, x, item, set_style('Times New Roman',220, True))
index += 1
# sys.exit();
#保存文件
workbook.save('demo.xls')
if __name__ =='__main__':
write_excel()
print ('创建demo.xlsx文件成功')
来源:https://blog.csdn.net/ren_273086429/article/details/79072553
标签:python,list,excel
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python bsddb模块操作Berkeley DB数据库介绍
2024-01-18 05:32:02
win10系统配置GPU版本Pytorch的详细教程
2023-07-21 19:30:38
![](https://img.aspxhome.com/file/2023/1/78541_0s.png)
Python实现程序的单一实例用法分析
2023-01-08 11:38:14
python pandas库的安装和创建
2023-09-25 22:49:02
![](https://img.aspxhome.com/file/2023/7/98827_0s.png)
python range实例用法分享
2021-09-28 02:54:46
python数据可视化的那些操作你了解吗
2023-11-04 15:18:55
![](https://img.aspxhome.com/file/2023/8/76908_0s.png)
JS实现为排序好的字符串找出重复行的方法
2024-04-10 10:49:53
运用Python巧妙处理Word文档的方法详解
2023-11-13 16:58:29
![](https://img.aspxhome.com/file/2023/3/104923_0s.jpg)
Python排序算法之插入排序及其优化方案详解
2021-04-03 05:39:31
![](https://img.aspxhome.com/file/2023/6/72086_0s.png)
DIV+CSS高度自适应网页代码实例
2008-09-20 08:00:00
![](https://img.aspxhome.com/file/UploadPic/20089/20/20089208546752s.jpg)
JavaScript设计模式之代理模式简单实例教程
2024-04-22 12:54:07
![](https://img.aspxhome.com/file/2023/9/136009_0s.png)
Python环境下搭建属于自己的pip源的教程
2021-12-19 05:57:54
Python如何实现小程序 无限求和平均
2023-04-13 20:07:40
Javascript+XMLHttpRequest+asp.net无刷新读取数据库数据
2024-01-17 17:32:18
Flask处理Web表单的实现方法
2021-10-20 17:13:36
详解python发送各类邮件的主要方法
2023-07-27 11:08:50
微信小程序开发之选项卡(窗口底部TabBar)页面切换
2024-03-08 08:19:29
![](https://img.aspxhome.com/file/2023/7/56387_0s.gif)
在Pandas DataFrame中插入一列的方法实例
2021-08-17 19:39:18
Dreamweaver MX打造弹出“向导”
2009-07-21 12:41:00
![](https://img.aspxhome.com/file/UploadPic/20071/200713110227823s.jpg)
Mysql性能优化案例研究-覆盖索引和SQL_NO_CACHE
2024-01-25 12:58:00
![](https://img.aspxhome.com/file/2023/3/107893_0s.png)