阅读 191

xlwings 格式

xlwings 格式

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.FontStyleprint('字体名称:', 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 = 20sheet.range('B1').api.Font.Bold = True
sheet.range('B1').api.Font.Color = 0x0000ffsheet.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 = 1sheet.range('C1').api.Borders(5).Weight = 2# 从范围中每个单元格的左下角到右上角的边框sheet.range('D1').api.Borders(6).LineStyle = 1sheet.range('D1').api.Borders(6).Weight = 2# 左边框,虚线sheet.range('C3').api.Borders(7).LineStyle = 2sheet.range('C3').api.Borders(7).Weight = 2# 顶边框,双点划线sheet.range('C3').api.Borders(8).LineStyle = 5sheet.range('C3').api.Borders(8).Weight = 2# 底部边框,直线,设置边框粗细为2sheet.range('C3').api.Borders(9).LineStyle = 1sheet.range('C3').api.Borders(9).Weight = 2# 右边框,点划线sheet.range('C3').api.Borders(10).LineStyle = 4sheet.range('C3').api.Borders(10).Weight = 2

复制代码


文章分类
后端
文章标签
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐