is there any way to create a .xlsm file from scratch in python?

后端 未结 3 933
感动是毒
感动是毒 2021-01-22 16:35

I am using python 3.8.1 on a mac and am trying to create a .xlsm file from scratch. I have looked at openpyxl and xlsxwriter, both of them are able to create

3条回答
  •  心在旅途
    2021-01-22 17:05

    It appears as though an XLSM file is a zipped Excel file, containing macros, etc.

    I was able to find a potential fix here using openpxyl:

    import openpyxl as px
    from openpyxl import load_workbook
    import os
    ...
    wbname='orig_fname.xlsm'
    wb = load_workbook(filename=wbname, keep_vba=True)
    ...
    wb.save('temp.xlsm')
    os.rename('temp.xlsm', wbname)
    

    Please let me know if it works for you.

提交回复
热议问题