Home > Backend Development > Python Tutorial > How to change font in python

How to change font in python

步履不停
Release: 2019-07-03 10:18:53
Original
13939 people have browsed it

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
Copy after login

# 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)
Copy after login
#=====常用字体颜色配置数值===========
# BLACK = 'FF000000'
# WHITE = 'FFFFFFFF'
# RED = 'FFFF0000'
# DARKRED = 'FF800000'
# BLUE = 'FF0000FF'
# DARKBLUE = 'FF000080'
# GREEN = 'FF00FF00'
# DARKGREEN = 'FF008000'
# YELLOW = 'FFFFFF00'
# DARKYELLOW = 'FF808000'
#====================================
Copy after login

# Set the font format

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

# 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')
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template