pip install --upgrade xlwings
打开带密码的excel:
import xlwings as xw
app = xw.App(visible=True, add_book=False)
wb = app.books.open(r"d:\test.xlsx", password="123")
###
### TODO
###
wb.save(r"d:\test2.xlsx", password='')
wb.close()
app.quit()
复制粘贴excel的内容:
# 把sht2的值复制到sht1
sht1= wb1.sheets['sheet1']
sht2= wb2.sheets['sheet1']
sht1.range('AK2').value=sht2.range('Y2').expand('table').value
# 把sht2的列复制到sht1去
sht1= wb1.sheets['sheet1']
sht2= wb2.sheets['sheet1']
sht2.api.Columns('Y:BQ').Copy(sht1.api.Columns('AK:CC'))
# 将多个wb2的sheet copy到wb1的status sheet后面
sht1= wb1.sheets['sheet1']
sht2= wb2.sheets['sheet1']
wb2.sheets['summary report','detail report','Backlog','summary GIT'].api.Copy(After=wb1.sheets['Status'].api)