简体   繁体   English

在 Python 2.7 中分配 styleObj 后,如何使用 sheet['A'].style/styleObj 分配样式?

[英]How to assign a style using sheet['A'].style/styleObj after styleObj has been assigned in Python 2.7?

Problem with sheet['A'].style/styleObj in Python 2.7 Python 2.7 中 sheet['A'].style/styleObj 的问题

What might be wrong?可能有什么问题?

import openpyxl
from openpyxl.styles import Font, NamedStyle
# create new file
wb = openpyxl.Workbook()
# read active sheet
sheet = wb.get_active_sheet()
# give new name parameters 
italic24Font = Font(size=24, italic=True)
styleObj = NamedStyle(font=italic24Font)
sheet['A'].style/styleObj
sheet['A1'] = 'Hello world!'

Thanks everyone for your help.感谢大家的帮助。 I found a correct version of the code:我找到了正确版本的代码:

import openpyxl
from openpyxl.styles import Font, NamedStyle
# create new file
wb = openpyxl.Workbook()
# read active sheet
sheet = wb['Sheet']

# give new name parameters 
italic24Font = NamedStyle(name="italic24Font")
italic24Font.font = Font(size=24, italic=True)
sheet['A1'].style = italic24Font
sheet['A1'] = 'Hello world!'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM