Home  >  Article  >  Backend Development  >  How to change font in python

How to change font in python

步履不停
步履不停Original
2019-07-03 10:18:5313899browse

How to change font in python

# 1. First import the classes that can specify the cell font, color, and alignment.

from openpyxl.styles import Font, colors, Alignment

# 2. Configure the font format as: style (Times New Roman), size (11), italic (flase), color (black), bold (flase), you can modify it according to your needs

font_style = Font(name='Times New Roman', size=11, italic=False, color='FF000000', bold=False)
#=====常用字体颜色配置数值===========
# BLACK = 'FF000000'
# WHITE = 'FFFFFFFF'
# RED = 'FFFF0000'
# DARKRED = 'FF800000'
# BLUE = 'FF0000FF'
# DARKBLUE = 'FF000080'
# GREEN = 'FF00FF00'
# DARKGREEN = 'FF008000'
# YELLOW = 'FFFFFF00'
# DARKYELLOW = 'FF808000'
#====================================

# Set the font format

sheet1.cell(row=i,column=1).font=font_style

# Set the font alignment. Here are vertical centering and horizontal centering. In addition to center, you can also use parameters such as right and left.

sheet1.cell(row=i,column=1).alignment = Alignment(horizontal='center', vertical='center')

Recommended related tutorials: Python video tutorial

The above is the detailed content of How to change font in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more