转换的时候值保留值,txt里面不写公式,data_only=True

This commit is contained in:
zhang hongbo 2026-01-07 11:35:36 +08:00
parent de4e1083af
commit b5c28423fa
2 changed files with 4 additions and 4 deletions

View File

@ -11,7 +11,7 @@ with open(cfg_path, 'r', encoding='utf-8') as f:
def read_table(file_path, sheet_name=None):
if file_path.lower().endswith('.xlsx'):
workbook = openpyxl.load_workbook(file_path)
workbook = openpyxl.load_workbook(file_path, data_only=True)
sheet = workbook[sheet_name] if sheet_name else workbook.active
fieldnames = [cell.value for cell in sheet[1]]
rows = list(sheet.iter_rows(values_only=True))[2:]

View File

@ -52,7 +52,7 @@ if os.path.isfile(cfg_files_path):
def read_table(file_path, sheet_name=None):
if file_path.lower().endswith('.xlsx'):
workbook = openpyxl.load_workbook(file_path)
workbook = openpyxl.load_workbook(file_path, data_only=True)
sheet = workbook[sheet_name] if sheet_name else workbook.active
fieldnames = [cell.value for cell in sheet[1]]
rows = list(sheet.iter_rows(values_only=True))[2:]
@ -81,8 +81,8 @@ for file_cfg in file_list:
target_file_path = os.path.join(current_dir, target_dir, file_cfg["out_file"])
sheet_name = file_cfg["sheet_name"]
# 读取XLSX文件
workbook = openpyxl.load_workbook(source_file_path)
# 读取XLSX文件data_only=True 确保读取公式的计算值而非公式本身
workbook = openpyxl.load_workbook(source_file_path, data_only=True)
sheet = workbook[sheet_name] if sheet_name else workbook.active
# 将数据写入TXT文件