标签:write create col work get 读文件 import excel gen
1 inwb=openpyxl.load_workbook(Path_generate) 2 Sheetnames=inwb.get_sheet_names() 3 ws=inwb.get_sheet_by_name(Sheetnames[0])
1 rows=ws.max_row 2 cols=ws.max_column
1 print(ws.cell(1,1).value)
1 outwb=openpyxl.Workbook() 2 outws=outwb.create_sheet(index=0)
1 outws.cell(row, col).value = row * 2 # 写文件
1 saveExcel = "D:\\work\\Excel_txtProcesss\\test.xlsx" 2 outwb.save(saveExcel) # 一定要记得保存
1 def readExel(self): 2 filename = r‘D:\work\Excel_txtProcesss\new-微博-合并\58.xlsx‘ 3 inwb = openpyxl.load_workbook(filename) # 读文件 4 5 sheetnames = inwb.get_sheet_names() # 获取读文件中所有的sheet,通过名字的方式 6 ws = inwb.get_sheet_by_name(sheetnames[0]) # 获取第一个sheet内容 7 8 # 获取sheet的最大行数和列数 9 rows = ws.max_row 10 cols = ws.max_column 11 for r in range(1, rows): 12 for c in range(1, cols): 13 print(ws.cell(r, c).value) 14 if r == 10: 15 break
1 def writeExcel(self): 2 outwb = openpyxl.Workbook() # 打开一个将写的文件 3 outws = outwb.create_sheet(index=0) # 在将写的文件创建sheet 4 for row in range(1, 70000): 5 for col in range(1, 4): 6 outws.cell(row, col).value = row * 2 # 写文件 7 print(row) 8 saveExcel = "D:\\work\\Excel_txtProcesss\\test.xlsx" 9 outwb.save(saveExcel) # 一定要记得保存
python 读取excel方法(最大行数:1048576)
标签:write create col work get 读文件 import excel gen
原文地址:https://www.cnblogs.com/smartisn/p/14928760.html