Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.1 kB
3
Indexable
Never
def save(frames, path_save, formats=None, dttm='yyyy-mm-dd'):
    options = {'strings_to_formulas': False, 'strings_to_urls': False}

    writer = pd.ExcelWriter(engine='xlsxwriter', path=path_save, engine_kwargs={'options': options}, date_format=dttm,
                            datetime_format=dttm)
    for k, v in frames.items():

        v.to_excel(writer, sheet_name=k, index=False)

        if formats != None and k in formats.keys():
            workbook = writer.book
            worksheet = writer.sheets[k]
            for ke, va in formats[k].items():
                if ke == 'row':
                    for key, value in formats[k][ke].items():
                        cell_format = workbook.add_format(value)
                        worksheet.set_row(key + 1, 15, cell_format)
                if ke == 'column':
                    for key, value in formats[k][ke].items():
                        cell_format = workbook.add_format(value)
                        worksheet.set_column(key + 1, key + 1, 9, cell_format=cell_format)