|
最近在寫一個處理excel的小工具,在設(shè)置excel字體,框線,對齊方式時碰了壁,還好找到如下博文,茅塞頓開。遂舉一反三。
https://blog.csdn.net/weixin_37577134/article/details/89048798

運用該博主的方法,我們先在excel把自己想要的格式設(shè)置出來:
‘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
|