[英]Python - Save Excel Spreadsheet without the Data Connection
我有一堆 Excel 電子表格(通過 ODBC)連接到數據庫。 我有一個 Python 腳本,它打開每張工作表,調用 RefreshAll() 更新數據,執行 SaveAs() 將刷新的文件放在共享文件夾中。
但在此過程中,我寧願刪除數據連接,這樣用戶就不能要求再次刷新數據,也不能操縱 SQL 查詢來獲取他們不應該訪問的其他數據。
wb = xl.workbooks.open(file, 2, False, None, None, 'password') # open workbook
xl.Visible = True # for testing
wb.RefreshAll()
wb.SaveAs(fileDest)
xl.Quit()
這有效...
wb = xl.workbooks.open(file, 2, False, None, None, 'password') # open workbook
xl.Visible = True # for testing
wb.RefreshAll()
for conn in wb.Connections:
conn.Delete()
wb.SaveAs(fileDest)
xl.Quit()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.