因此,如下面的代码所示,除了单元格'A1'之外,A列中的所有单元格都获得字体样式'italic24Font'。
import openpyxl
from openpyxl.styles import Font
wb = openpyxl.Workbook()
sheet = wb["Sheet"]
italic24Font = Font( size = 24, italic = True )
column = sheet.column_dimensions['A']
column.font = italic24Font
sheet['A1'] = 'Hello world'
wb.save( 'test.xlsx' )
答案 0 :(得分:0)
看起来当您写入单元格时,列设置会重置为默认值。
您可以在将内容写入单元格时将字体设置为列
<强> EX:强>
import openpyxl
from openpyxl.styles import Font
wb = openpyxl.Workbook()
sheet = wb["Sheet"]
italic24Font = Font( size = 24, italic = True, color='00FF0000' )
column = sheet.column_dimensions['A']
column.font = italic24Font
sheet['A1'] = 'Hello world'
sheet['A1'].font = italic24Font
wb.save( 'test.xlsx' )
print "Done!!!"
我有同样的问题。不确定它是否是openpyxl的错误