
python
文章平均质量分 70
python
wind12370
这个作者很懒,什么都没留下…
展开
-
Python用xlrd读取excel文件
Python用xlrd读取excel文件import xlrddef read_excel():wb=xlrd.open_workbook(r’D:\pycharm\APP\3.xlsx’)# ws=wb.sheet_names()# print(ws)ws=wb.sheet_by_index(1)#通过索引拿到工作表sheetlist1=[]for i in range(1,ws.nrows):#行和列的索引dic = {}dic[‘姓名’]=ws.cell_value(i,0)di原创 2020-08-24 19:18:17 · 568 阅读 · 0 评论 -
python读取excel文件,Openpyxl+列表解析式
python读取excel文件,Openpyxl+列表解析式import openpyxldef read_excel():wb=openpyxl.load_workbook(r’D:\pycharm\APP\3.xlsx’)#打开1个指定的工作簿# ws=wb.sheetnames#获取工作簿所有工作表sheet# print(ws)ws1=wb[‘测试1’]#通过工作表名’测试1’获取工作表sheetdatas=list(ws1.rows)#获取指定工作表sheet所有行# title原创 2020-08-24 18:39:08 · 689 阅读 · 0 评论 -
Python读取txt文件,用openpyxl模块写入到excel
Python读取txt文件,用openpyxl模块写入到excelimport openpyxlcontents=[]def read_txt():file_txt=open(r’D:\pycharm\APP\3.txt’,‘r’,encoding=‘utf-8’)#打开txt文件for i in file_txt:contents.append(i.split())#遍历txt文件内容存放到列表file_txt.close()print(contents)def write_excel(原创 2020-08-24 16:46:58 · 2688 阅读 · 0 评论