excel文件公式数据为None怎么办?
# 原因,包问题
我用openpyxl操作完以后,带公式的值就读取不出来了;
# 编写操作,打开一个目录下的所有xlsx文件功能
# 所需要的依赖
import win32api import win32con import win32process from win32com import client import psutil
def kill(p_name="excel.exe"): pids = psutil.pids() for pid in pids: try: p = psutil.Process(pid) except: continue if p.name().lower() == p_name: print(f"杀死{p_name}") cmd = f'taskkill /F /IM {p.name()}' os.system(cmd)
def open_all_excel(): lang_col_mapper = get_lang_col_mapper() # xlApp = client.Dispatch("Excel.Application") for lang_key, _ in lang_col_mapper.items(): # print(lang_key) # if "en" not in lang_key: # continue file_dir = os.path.join(datasheetDir, lang_key) file_list = walkFile(file_dir) count_num = 0 xlApp = client.Dispatch("Excel.Application") for file_name in file_list: count_num += 1 if file_name.startswith("~"): continue if not (file_name.endswith(".xlsx")): continue excel_file = f"/{lang_key}/{file_name}" file_src = os.path.join(datasheetDir, lang_key,file_name) file_src = change_path_platform(file_src=file_src) # xlApp = client.Dispatch("Excel.Application") try: xlApp.Visible = False except: try: xlApp.Visible = False except: try: xlApp.Visible = False except: xlApp.Visible = False books = xlApp.Workbooks.Open(file_src) xlApp.DisplayAlerts = False logger.info(f"第{_-4}语言 {lang_key} {count_num} {file_src}已重新打开") try: books.SaveAs(file_src) except Exception as e: print(f"ERROR : {file_src} {e}") books.Close() xlApp.DisplayAlerts = True xlApp.Quit() kill() time.sleep(5)
-----------------------------------------------------------------------------------------------------------------------------------------