Python 读写excel
来源:互联网 发布:怎么申请免费的域名 编辑:程序博客网 时间:2024/06/03 15:27
安装模块的方法:pip install xlrd
__author__ = 'Administrator'import xlrd,os,xlwtdef open_excel(filename): data=xlrd.open_workbook(filename) return datadef getTableByIndex(filename,index=0): data=open_excel(filename) table=data.sheet_by_index(0) #data.sheet_by_name("") #table=data.sheets()[index] colsName=table.row_values(0) rowNum=table.nrows colNum=table.ncols list=[] for i in range(1,rowNum): row=table.row_values(i) dic={} for j in range(0,colNum): dic[colsName[j]]=row[j] list.append(dic) return listdef writeTable(li,filename,index=0): file=xlwt.Workbook() table = file.add_sheet('info',cell_overwrite_ok=True) #写入数据table.write(行,列,value) a=list(li[0].keys()) for i in range(0,len(li)): for j in range(0,len(li[i])): table.write(i,j,li[i][a[j]]) file.save(filename)def main(): table=getTableByIndex("C:/Users/Administrator/Desktop/计算机学院2017级博士生拟录取名单.xlsx",index=0) writeTable(table,"C:/Users/Administrator/Desktop/名单.xlsx",index=0) print(table)if __name__=="__main__": main()
阅读全文
0 0
- 【python】python读写excel
- python 读写excel
- Python 读写 Excel
- Python读写Excel
- python中读写excel
- python 读写excel
- python 读写 Excel
- python 读写excel
- python读写Excel文件
- python读写excel文件
- Python读写excel文件
- python读写excel
- Python 读写Excel文件
- Python读写Excel
- python读写excel
- Python读写Excel
- Python读写Excel
- python + excel 读写学习
- Zabbix 系列博客教程目录
- Android的事件传递机制
- Kotlin学习资料汇总
- Java基础day01
- HBuilder配置自动编译Less(包含less-plugin-functions)
- Python 读写excel
- 写给Android App开发人员看的Android底层知识(2)(转自包老师)
- ios::sync_with_stdio(false);
- 乐驾项目博客-3
- Tree Recovery UVA
- 返回数组最小正整数
- 记一次失败的比赛
- MySql通过update语句交换两行记录非唯一的属性
- 机房重构再次相遇UML