refresh.py 688 B

1234567891011121314151617181920212223242526
  1. import win32com.client
  2. from pathlib import Path
  3. def refresh(filename_str: str):
  4. filename = Path(filename_str)
  5. excel = win32com.client.Dispatch("Excel.Application")
  6. excel.DisplayAlerts = False
  7. print(f"Refresh '{filename.resolve()}'")
  8. wb = excel.Workbooks.Open(filename.resolve())
  9. try:
  10. for source in wb.LinkSources(1):
  11. print(" --> " + source)
  12. if Path(source).exists():
  13. excel.Workbooks.Open(source)
  14. else:
  15. print(" !! does not exist !!")
  16. except TypeError:
  17. print(" --> " + "no LinkSources")
  18. wb.RefreshAll()
  19. wb.Save()
  20. wb.Close(True)
  21. excel.Application.Quit()