首页 > Windows开发 > 详细

xlwings 格式

时间:2021-05-04 17:43:48      阅读:32      评论:0      收藏:0      [点我收藏+]

xlwings 单元格格式设置

import xlwings as xw

wb = xw.Book(1.xlsx)

ws = xw.sheets[0]

ws.range(1,1).expand(right).value=[1,2,3,4]

ws.range(2,4).expand(down).options(transpose=True).value = [10,20,30,40]

wb.save()

wb.close()

app = xw.App(add_book = False)
wb = app.books.open(1.xlsx)
sheet = wb.sheets[0]

sheetFont_name = sheet.range(B1).api.Font.Name

sheetFont_size = sheet.range(B1).api.Font.Size

sheetFont_bold = sheet.range(B1).api.Font.Bold

sheetFont_color = sheet.range(B1).api.Font.Color

sheetFont_FontStyle = sheet.range(B1).api.Font.FontStyle

print(字体名称:, sheetFont_name)
print(字体大小:, sheetFont_size)
print(字体是否加粗:, sheetFont_bold)
print(字体颜色:, sheetFont_color)
print(字体类型:,sheetFont_FontStyle)

sheet.range(B1).api.Font.Name = 微软雅黑
sheet.range(B1).api.Font.Size = 20
sheet.range(B1).api.Font.Bold = True
sheet.range(B1).api.Font.Color = 0x0000ff
sheet.range(B1).api.Font.FontStyle = "Bold Italic"

sheet.range(B1).api.HorizontalAlignment = -4108    # -4108 水平居中
sheet.range(B1).api.VerticalAlignment = -4130      # -4108 垂直居中
sheet.range(B1).api.NumberFormat = "0.00"          # 设置单元格的数字格式 

# 从范围中每个单元格的左上角到右下角的边框
sheet.range(C1).api.Borders(5).LineStyle = 1
sheet.range(C1).api.Borders(5).Weight = 2

# 从范围中每个单元格的左下角到右上角的边框
sheet.range(D1).api.Borders(6).LineStyle = 1
sheet.range(D1).api.Borders(6).Weight = 2

# 左边框,虚线
sheet.range(C3).api.Borders(7).LineStyle = 2
sheet.range(C3).api.Borders(7).Weight = 2

# 顶边框,双点划线
sheet.range(C3).api.Borders(8).LineStyle = 5
sheet.range(C3).api.Borders(8).Weight = 2

# 底部边框,直线,设置边框粗细为2
sheet.range(C3).api.Borders(9).LineStyle = 1
sheet.range(C3).api.Borders(9).Weight = 2

# 右边框,点划线
sheet.range(C3).api.Borders(10).LineStyle = 4
sheet.range(C3).api.Borders(10).Weight = 2 

 

xlwings 格式

原文:https://www.cnblogs.com/Teyisang/p/14729367.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!