python3 读取写入Excel
2017-10-13 16:26
309 查看
①写入Excel:
import xlwt #xlwt用来写excel文件
new_workbook=xlwt.Workbook() #创建工作簿
new_sheet=new_workbook.add_sheet("SheetName_test") #创建表
new_sheet.write(0,0,"hello") #在第一行第一列写入 hello,想写到其它单元格,改变下标即可
new_workbook.save(r"NewCreateWorkbook.xls") #保存此表,取名为NewCreateWorkbook
②读取Excel:
import xlrd #xlrd用来读excel文件
workbook=xlrd.open_workbook(r"NewCreateWorkbook.xls") #打开Excel文件
sheet=workbook.sheet_by_index(0) #读取第一张表,下标为0,想读取其它表,改变下标即可
row=sheet.row_values(0) #row为第一行的内容,下标为0,想读取其它行,改变下标即可
col=sheet.col_values(0) #col为第一类的内容,下标为0,想读取其它列,改变下标即可
cell_value=sheet.cell(0,0).value #cell_value为第一行第一列单元格的内容,下标为(0,0),想读取其它单元格,改变下标即可
import xlwt #xlwt用来写excel文件
new_workbook=xlwt.Workbook() #创建工作簿
new_sheet=new_workbook.add_sheet("SheetName_test") #创建表
new_sheet.write(0,0,"hello") #在第一行第一列写入 hello,想写到其它单元格,改变下标即可
new_workbook.save(r"NewCreateWorkbook.xls") #保存此表,取名为NewCreateWorkbook
②读取Excel:
import xlrd #xlrd用来读excel文件
workbook=xlrd.open_workbook(r"NewCreateWorkbook.xls") #打开Excel文件
sheet=workbook.sheet_by_index(0) #读取第一张表,下标为0,想读取其它表,改变下标即可
row=sheet.row_values(0) #row为第一行的内容,下标为0,想读取其它行,改变下标即可
col=sheet.col_values(0) #col为第一类的内容,下标为0,想读取其它列,改变下标即可
cell_value=sheet.cell(0,0).value #cell_value为第一行第一列单元格的内容,下标为(0,0),想读取其它单元格,改变下标即可
相关文章推荐
- 用Python读取Word文档并写入Excel(二)
- Python读取和写入Excel文件[整]
- python中写入csv,excel显示、pandas读取csv文件的编码问题
- Python xlwd 读取excel xlwt 写入excel xlutils 修改excel
- python读写Excel文件--使用xlrd模块读取,xlwt模块写入
- python实战之实现excel读取、统计、写入的示例讲解
- Python 读取EXCEL(XLS、CSV)写入txt文件
- Python处理Excel 写入,读取和追加
- python实战之实现excel读取、统计、写入
- Python(11)萌新也能看懂之——用Python读取数据库,然后写入Excel里
- python 在excel文件中写入date日期数据,以及读取excel日期数据,如何在python中正确显示date日期。
- python使用xlwt读取文件写入Excel
- Python读取txt内容写入xlsx格式的excel中
- selenium+python关于登录的脚本代码,使用了读取excel以及向excel中写入测试结果的方法
- python实现读取excel写入mysql的小工具详解
- Python读取txt内容写入xls格式的excel中
- python读取txt数据写入excel
- Python中xlrd、xlwt、xlutils模块,实现在Excel读取和写入数据
- python读取excel指定列数据并写入到新的excel
- 基于python实现在excel中读取与生成随机数写入excel中