consolidator
/
ExcelPath.py
22 строки · 689.0 Байт
1import winreg
2
3class ExcelPath(object):
4""" Определитель точного пути к excel """
5def __init__(self) -> None:
6pass
7@staticmethod
8def get()->str:
9try:
10aReg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
11aKey = winreg.OpenKeyEx(aReg, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\excel.exe")
12oKey = winreg.QueryValueEx(aKey, "Path")
13if aKey: winreg.CloseKey(aKey)
14return f"{oKey[0]}excel.exe"
15except: raise
16
17if __name__=="__main__":
18try:
19ss = ExcelPath.get()
20print(ss)
21except Exception as exp:
22print(exp)