Python xlrd和xlwt读写Excel
2017-11-20 13:41
274 查看
简单基础的操作excel
读取Excel
import xlrd #获取excel book = xlrd.open_workbook(r"C:\Users\Allen\Desktop\随机性.xlsx") #获取excel表的数量 print(book.nsheets) #获取excel表的名字分别是什么 print(book.sheet_names()) #获取第一个表,更改index可以获取到不同的表 first_sheet = book.sheet_by_index(0) #获取表的第一行的数据,更改row的index可以得到不同行的数据 print(first_sheet.row_values(0)) #获取行为1,列为1的数据,即某个单元格的数据 cell = first_sheet.cell(1, 1) print(cell)
写入excel
import xlwt '''创建一个excel,并且使编码方式为utf8''' wb = xlwt.Workbook(encoding="utf8") #添加一个名字为Python的表,将要操作的表 sheet1 = wb.add_sheet("Python") #将Test写入到表中 sheet1.write(0, 0, "Test") #将excel进行保存命名 wb.save("Python.xls")
以上就是基础的使用xlrd和xlwt对于excel进行操作了,可以在这个上面进行丰富和添加完成更为复杂的操作,比如使用os定义excel保存位置啊这些,这里就不一一介绍了。
相关文章推荐
- Python简单读写Excel (xlwt, xlrd, xlutils)
- Python xlrd xlwt读写Excel
- 使用Python xlrd与xlwt模块读写Excel
- Python 读写操作Excel —— 安装第三方库(xlrd、xlwt、xlutils、openpyxl)
- [Python笔记] 使用xlrd和xlwt进行简单的excel表格读写操作
- Python.xlrd&xlwt -- Excel读写
- python - 通过加载第三方库xlrd/xlwt/xlsxwriter,来读写excel文件,不涉及图形操作
- 用python读写excel(xlrd、xlwt)
- python中使用xlrd、xlwt读写excel(xls格式)
- python操作Excel读写--使用xlrd和xlwt
- Python读写Excel:xlrd与xlwt
- 用python读写excel(xlrd、xlwt)
- 在python中使用xlrd,xlwt读写excel
- 【Python】excel读写操作 xlrd & xlwt
- python读写Excel文件--使用xlrd模块读取,xlwt模块写入
- 使用python读写操作同一个excel(xlrd,xlwt,xlutils)
- 使用python读写操作同一个excel(xlrd,xlwt,xlutils)
- 自己总结python用xlrd\xlwt读写excel
- Python xlrd、xlwt读写Excel
- 用python读写excel(xlrd、xlwt)