python - 通过python保存文件后现有条件格式被破坏
问题描述
我正在使用 python 中的代码打开一个现有的具有条件格式的 Excel 文件。代码打开文件,在其中添加一些数字,并以不同的名称将文件保存在不同的文件夹中。当我打开保存的新文件时,条件格式存在但工作方式不同。条件格式是一个数据栏,我在其中设置了最小值零和最大值 1。问题是最小值和最大值在新文件中不再保留,因为它们是在初始文件中设置的。具体来说,值为 0 时,条不完全为空(显示短条),而值为 1 时,条未完全满。
我确信导致这种情况的原因与文件中添加的数字无关,因为我在没有这一步的情况下运行了代码,问题仍然存在。
这是我正在使用的代码:
xfile = openpyxl.load_workbook('Output Predictions Prototype File.xlsx') # Opens the original excel output prediction file
sheet = xfile.get_sheet_by_name('Output Predictions') # Chooses the 'Output Prediction' sheet in the file
sheet['C5'] ='Report Date: ' + currentYear + '-' + currentMonth + '-' + currentDay #inserts report date in the format YYYY-MM-DD
Entity_name_and_code = Entity_names[i] + ' - (' + Entity_codes[i] +')' # Creates string with entity name and entity code
sheet['C7'] =Entity_name_and_code
sheet['D9'] = notch_to_rating_class[rating_predictions[i]] # Inserts the predicted rating in cell D9
# Inserts the predicted probabilities
sheet['D12'] = probabilities[i][4]
sheet['D13'] = probabilities[i][3]
sheet['D14'] = probabilities[i][2]
sheet['D15'] = probabilities[i][1]
sheet['D16'] = probabilities[i][0]
sheet['E19'] = 13-NA_counter_for_bank_i # Inserts the number of variables with availiable data
sheet['E20'] = NA_counter_for_bank_i # Inserts the number of variables with N/A data
filename='CFS_Prediction_' + Current_Year_Month_Day + '_' + Entity_codes[i] + '.xlsx' #Stores the name of the file in a string
file_path = 'C:\\Users\\Downloads\\Python Files - Projects\\Output Prediction Files\\' #File path were we want to save the files in
complete_file_name = file_path + filename # Complete file path with the file name at the end
xfile.save(complete_file_name)
解决方案
推荐阅读
- git - git 只跟踪一个没有任何文件的目录
- python - 无法使用 PySpark xgboost4j 保存模型
- ios - iTunesConnect:“无法加载您的一个或多个应用预览。再试一次。”
- c# - TFS 2018 API:可以访问工作项但不能访问工作项 API 端点
- pycharm - PyCharm 中 PyTorch 类的属性警告
- c# - 如何在 Visual Studio Sharepoint/Office Webpart 中导入引导程序?
- javascript - AWS SAM 本地启动 API:设置 lambda nodejs 12.x 标志(例如 --experimental-modules)?
- go - 如何制作结构的复制切片
- reverse-engineering - 获取 Steam 用户的库存上下文
- qt - 使用 Qt 项目文件生成 doxygen 文档