from openpyxl import Workbook wb = Workbook() ws = wb.active ''' 指定sheet wb.create_sheet("mySheet") ws = wb.get_sheet_by_name("mySheet") ''' i = 1 j = 1 for val in headers: ws.cell(row=i,column=j,value=val) j = j + 1 i = 2 for row in data_lines: j = 1 for val in row: ws.cell(row=i,column=j,value=val) j = j + 1 i = i + 1 ### 冻结窗口,单元格上面的行和左边的列将会冻结(单元格所在的行和列不会被冻结) # 冻结第一行 ws.freeze_panes = ws['A2'] # 冻结第一列 ws.freeze_panes = ws['B1'] # 冻结第一行第一列 ws.freeze_panes = ws['B2'] wb.save(expfile)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。