最近在写一个处理excel的小工具,在设置excel字体,框线,对齐方式时碰了壁,还好找到如下博文,茅塞顿开。遂举一反三。
https://blog.csdn.net/weixin_37577134/article/details/89048798

运用该博主的方法,我们先在excel把自己想要的格式设置出来:
‘One’:加粗,左对齐靠下
‘Two’:倾斜,居中靠下
‘Three’:下划线,左对齐靠上
‘Four’:左对齐居中
‘Five’:右对齐靠下
全框线,粉色
wb = xw.Book(r'F:\PythonData\xlwings\Style.xlsx') sht_color = sht.range((1,1)).color sht.range((3,1)).color = (255, 153, 255) sht_BoldA = sht.range((1,1)).api.Font.Bold sht_BoldB = sht.range((1,2)).api.Font.Bold sht.range((3,1)).value = 'A3' sht.range((3,1)).api.Font.Bold = True sht_Fontstyle = sht.range((1,2)).api.Font.FontStyle sht.range((3,2)).value = 'B3' sht.range((3,2)).api.Font.FontStyle = "倾斜" sht_Underline = sht.range((1,3)).api.Font.Underline sht.range((3,3)).value = 'C3' sht.range((3,3)).api.Font.Underline = 2 sht_style = sht.range((1,1),(1,5)).api.Borders.LineStyle sht.range((3,1),(3,3)).api.Borders.LineStyle = 1 sht_HA_A1 = sht.range((1,1)).api.HorizontalAlignment sht_HA_A2 = sht.range((1,2)).api.HorizontalAlignment sht_HA_A5 = sht.range((1,5)).api.HorizontalAlignment sht_VA_A3 = sht.range((1,3)).api.VerticalAlignment sht_VA_A4 = sht.range((1,4)).api.VerticalAlignment sht_VA_A5 = sht.range((1,5)).api.VerticalAlignment
|