def add_editor_list_to_excel(case=None):
'''save editor tool list order to the excel input file, "proposals.xlsx".
The list order will be saved to a new worksheet, "edit". Subsequent saved
lists will overwrite previous worksheets. Change the worksheet name of
previously saved worksheets from "edit" to something else prior to running
this function if they are to be preserved within the workbook.
The routine reads the case_dill.pkl file - this provides a write path to
the correct case study folder and excel "proposals.xlsx" file.
Then the routine reads the editor-produced p_new_order.pkl file and writes
it to the new worksheet "edit" in the proposals.xlsx file.
input
case (string)
The case study name (and consequently, the write file path).
This variable will default to the stored case study name contained
within the "dill/case_dill.pkl" file if no input is supplied by
the user.
'''
if not case:
try:
case = pd.read_pickle('dill/case_dill.pkl').case.value
except OSError:
print('case variable not found,',
'tried to find it in "dill/case_dill.pkl"',
'without success\n')
return
xl_str = 'excel/' + case + '/proposals.xlsx'
df = pd.read_pickle('dill/p_new_order.pkl')
df = df.reset_index()[['empkey']]
df.index = df.index + 1
df.index.name = 'order'
ws_dict = pd.read_excel(xl_str, index_col=0, sheetname=None)
ws_dict['edit'] = df
with pd.ExcelWriter(xl_str, engine='xlsxwriter') as writer:
for ws_name, df_sheet in ws_dict.items():
df_sheet.to_excel(writer, sheet_name=ws_name)
# Pretty print a dictionary...
matplotlib_charting.py 文件源码
python
阅读 28
收藏 0
点赞 0
评论 0
评论列表
文章目录