python-23-读写excel文件
来源:互联网 发布:java和scala 编辑:程序博客网 时间:2024/06/01 07:52
我们尝试添加总分列,并计算各个同学的总分成绩
直接获取某一行所有值,第二项是从第几个格子开始
import xlrdbook = xlrd.open_workbook('demo.xlsx')#sheets可以获取所有的表,返回一个sheet对象book.sheets()#另一种获取sheet的方法sheet = book.sheet_by_index(0)# 访问行数sheet.nrows# 访问列数sheet.ncols# 获取单元格内容cell = sheet.cell(0,0)# 获取单元格类型,返回的是枚举值,1对应xlrd.XL_CELL_TEXT;2对应xlrd.XL_CELL_NUMBERcell.ctype# 获取单元格的内容(unicode)cell.value# 获取一行,返回一个列表,每一项都是一个sheet对象sheet.row(1,1)# 同样,col类似
添加单元格,这个添加操作需要引入xlwt
import
wbook = xlwt.Workbook()
wsheet = wbook.add_sheet(‘sheet1’)
解代码:
#coding:utf8import xlrd,xlwtrbook = xlrd.open_workbook('demo.xlsx')rsheet = rbook.sheet_by_index(0)nc = rsheet.ncolsrsheet.put_cell(0,nc,xlrd.XL_CELL_TEXT,u'总分',None)for row in range(1,rsheet.nrows): t = sum(rsheet.row_values(row,1)) rsheet.put_cell(row,nc,xlrd.XL_CELL_NUMBER,t,None)wbook = xlwt.Workbook()wsheet = wbook.add_sheet(rsheet.name)style = xlwt.easyxf('align:vertical center,horizontal center')for r in range(rsheet.nrows): for c in range(rsheet.nols): wsheet.writes(r,c,rsheet.cell_value(r,c),style) wbook.save('output.xlsx')
0 0
- python-23-读写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文件
- C语言条件编译详解
- HDU 3974-Assign the task(dfs构建结构+裸线段树)
- 收集service源码分析文章
- 1074: 人见人爱A+B
- 字符编码笔记:ASCII,Unicode和UTF-8
- python-23-读写excel文件
- SharePreference 跨进程使用测试
- bzoj1084: [SCOI2005]最大子矩阵
- SSAS:OLE DB 错误: OLE DB 或 ODBC 错误 : Login failed for user 'NT Service\MSSQLServerOLAPService'
- c++数据结构 共享栈的实现
- centos yum -y mysql-server找不到源
- win10系统崩溃经验汇总
- 代码
- POJ