Python快速設置Excel表格邊框


import xlwings as xw
#打開存好的excel
app = xw.App() #設置應用
wb = xw.Book("E:/Data/小蜜蜂超市銷售報表.xlsx") #打開文件
ws = wb.sheets['Sheet1'] #選擇表格

last_column = ws.range(1, 1).end('right').get_address(0, 0)[0] #獲取最后列
last_row = ws.range(1, 1).end('down').row #獲取最后行

a_range = f'A1:{last_column}{last_row}' #生成表格的數據范圍

#設置邊框
ws.range(a_range).api.Borders(8).LineStyle = 1 #上邊框
ws.range(a_range).api.Borders(9).LineStyle = 1 #下邊框
ws.range(a_range).api.Borders(7).LineStyle = 1 #左邊框
ws.range(a_range).api.Borders(10).LineStyle = 1 #右邊框
ws.range(a_range).api.Borders(12).LineStyle = 1 #內橫邊框
ws.range(a_range).api.Borders(11).LineStyle = 1 #內縱邊框

#保存並關閉excel
wb.save("E:/Data/小蜜蜂超市銷售報表2.xlsx")
wb.close()
app.quit()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM