python xlwings excel 根据列排序

import xlwings as xw
file = 'a.xlsx'
app = xw.App(visible=False, add_book=False)
app.display_alerts = False
app.screen_updating = False
wbk = app.books.open(file)
sheet = wbk.sheets['Sheet 1']

# 以下是根据G列排序,我的表头是在第二行,所以是G2
# Order1说明:1代表升序,2代表降序
sheet.range('G2').api.Sort(Key1=sheet.range('G2').api, Order1=2)

可以参考VBA的文档
https://docs.microsoft.com/zh-CN/office/vba/api/Excel.Range.Sort

你可能感兴趣的:(python,excel,xlwings,vba)