将样式附加到excel的完整行

时间:2017-12-09 19:07:42

标签: python excel openpyxl

我在" python"中编码使用" openpyxl"试图设置字体' Arial'在Excel文件中的某些列,但我的代码写行很好,但没有字体 在将任何内容写入文件之前是否有字体解决方案?

尝试设置字体时隐藏的当前代码

                ## SELECTING THE FILE     
                wb = openpyxl.load_workbook(filepath)

                ## CREATTING WORKSHEET IF DOESNT EXIST               
                if bool(x['workbook_name'] in wb.get_sheet_names()) == False:
                    wb.create_sheet(x['workbook_name'])
                    sheet = wb.get_sheet_by_name(x['workbook_name'])

                    sheet['A1'] = 'Tel'
                    sheet['B1'] = 'Fax'
                    sheet['C1'] = 'email'
                    sheet['D1'] = 'address'
                    sheet['E1'] = 'date'

                    sheet.column_dimensions['A'].font = Font(name="Arial")
                    sheet.column_dimensions['B'].font = Font(name="Arial")
                    sheet.column_dimensions['C'].font = Font(name="Arial")
                    sheet.column_dimensions['D'].font = Font(name="Arial")
                    sheet.column_dimensions['E'].font = Font(name="Arial")


                ## DELETE WORKSHEET "SHEET" IF EXISTS
                if bool('Sheet' in wb.get_sheet_names()) == True:
                    ws = wb.get_sheet_by_name('Sheet')
                    wb.remove_sheet(ws)                        

                ## SELECT SHEET
                sheet = wb.get_sheet_by_name(x['workbook_name'])

                ## APPEND ROW
                sheet.append([_tel1,_model,_manfc,x['note'],time.strftime("%d/%m/%Y")])

                ## SAVE WORKBOOK
                wb.save(filepath)

现在我有this link,但它并没有真正帮助,不清楚

即使这个简单的代码也会出现同样的问题,但是列被隐藏了

wb = openpyxl.load_workbook('test101.xlsx')
sheet = wb.get_sheet_by_name('Sheet')
sheet['A1'].font = Font(name='Arial')
sheet.append(['hello','world'])
wb.save('test101.xlsx')

0 个答案:

没有答案