• 投稿

历史模拟器:崇祯 圣旨自动生成器

2369
2
2026-05-18 04:54:52
33
11
50
3
写了一个python的小工具,由Excel表自动生成圣旨,方便玩家复制粘贴 import pandas as pd def num_to_chinese(n: int) -> str:   chinese_digits = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']   if n <= 0:     return ''   if n <= 10:     return chinese_digits[n] if n != 10 else '十'   if n < 20:     return '十' + (chinese_digits[n % 10] if n % 10 != 0 else '')   if n < 100:     tens = n // 10     ones = n % 10     if ones == 0:       return chinese_digits[tens] + '十'     else:       return chinese_digits[tens] + '十' + chinese_digits[ones]   return str(n) def process_excel(excel_path: str, output_txt_path: str):   target_sheets = ['军事部分', '内政部分', '外交部分', '其他指令']   xls = pd.ExcelFile(excel_path)   available_sheets = xls.sheet_names   all_output_lines = []   for sheet in target_sheets:     if sheet not in available_sheets:       print(f"警告:工作表 '{sheet}' 不存在,跳过")       continue     df = pd.read_excel(excel_path, sheet_name=sheet, dtype=str)     if '是否启用' not in df.columns:       print(f"警告:工作表 '{sheet}' 中缺少'是否启用'列,跳过")       continue     if df.shape[1] < 2:       print(f"警告:工作表 '{sheet}' 列数不足,跳过")       continue     entries = []     counter = 1     for _, row in df.iterrows():       enable_val = row['是否启用']       if pd.isna(enable_val):         continue       if str(enable_val).strip() == '是':         col0 = row.iloc[0]         col1 = row.iloc[1]         col0 = '' if pd.isna(col0) else col0         col1 = '' if pd.isna(col1) else col1         chinese_num = num_to_chinese(counter)         entry = f"{chinese_num}、{col0}\n{col1}\n"         entries.append(entry)         counter += 1     if entries:       all_output_lines.append(f"【{sheet}】")       all_output_lines.extend(entries)       all_output_lines.append('')    with open(output_txt_path, 'w', encoding='utf-8') as f:     f.write('\n'.join(all_output_lines))   print(f"处理完成!结果已保存至:{output_txt_path}") if __name__ == '__main__':   # 请根据实际情况修改文件路径   input_excel = 'input.xlsx'   output_txt = 'output.txt'   process_excel(input_excel, output_txt)
客服
顶部
赛事库 课堂 2021拜年纪