app = xw.App(visible=True, add_book=False)
wb = app.books.add()
sht = wb.sheets.active
b3 = sht.range('b3')
"""设置单元格大小"""
sht.autofit() # 自动调整单元格大小。
sht.range(1,4).column_width = 5 # 设置第4列 列宽。(1,4)为第1行第4列的单元格
sht.range(1,4).row_height = 20 # 设置第1行 行高
"""设置单元格 字体格式"""
b3.color = 255,200,255 # 设置单元格的填充颜色
b3.api.Font.ColorIndex = 3 # 设置字体的颜色,具体颜色索引见下方。
b3.api.Font.Size = 24 # 设置字体的大小。
b3.api.Font.Bold = True # 设置为粗体。
b3.api.HorizontalAlignment = -4108 # -4108 水平居中。 -4131 靠左,-4152 靠右。
b3.api.VerticalAlignment = -4130 # -4108 水平居中(默认)。 -4160 靠上,-4107 靠下, -4130 自动换行对齐。
b3.api.NumberFormat = "0.00" # 设置单元格的数字格式。
"""设置边框"""
# Borders(9) 底部边框,LineStyle = 1 直线。
b3.api.Borders(9).LineStyle = 1
b3.api.Borders(9).W
xlwings常用API
最新推荐文章于 2022-06-15 21:05:01 发布