样式示例
基本样式
from symphra_excel import Workbook
from symphra_excel.styles import CellStyle
with Workbook() as wb:
sheet = wb.create_worksheet("样式示例")
style = CellStyle()
style.set_font(name="Arial", size=12, bold=True, color="#FF0000")
style.set_background_color("#FFFF00")
style.set_border(left="thin", right="thin", top="thin", bottom="thin")
style.set_alignment(horizontal="center", vertical="center")
sheet.set_cell_value("A1", "样式化单元格")
sheet.apply_style("A1", style)
wb.save("styled_example.xlsx")
预定义样式
from symphra_excel import Workbook
from symphra_excel.styles import PredefinedStyles
with Workbook() as wb:
sheet = wb.create_worksheet("预定义样式")
sheet.set_cell_value("A1", "标题")
sheet.apply_style("A1", PredefinedStyles.title_style())
sheet.set_cell_value("A2", "表头")
sheet.apply_style("A2", PredefinedStyles.header_style())
sheet.set_cell_value("A3", 12345.67)
sheet.apply_style("A3", PredefinedStyles.currency_style())
wb.save("predefined_styles.xlsx")
相关文档