python - "xlwings" : does not support writing of .xlsm files? -


i've tried simple test using "xlwings_0.3.4" open excel .xltm file , save again, make sure vba modules kept. couldn't work.

if give file extension in save step, file saved .xlsx file. module carried along, extension change isn't recognized valid vba module. if not specify file extension, automatically saved .xlsx:

wb=xlwings.workbook('template.xltm') wb.save('outfile') wb.close() 

this gives xlsx file.

trying set file xlsm generates error:

wb.save('outfile.xlsm') wb.close() xl_workbook.saveas(path) 

will generate error:

xl_workbook.saveas(path) file "<comobject open>", line 7, in saveas pywintypes.com_error: (-2147352567, 'exception occurred.', (0, u'microsoft          excel', u'this extension can not used selected file type. change   file extension in file name text box or select different file type changing save type.', u'xlmain11.chm', 0, -2146827284), none) 

this seems inherent application object returned getactiveobject('excel.application').

is there switch (like 'keep_vba=true' switch in openpyxl?), or not possible save xlsm files xlwings?

what trying xl_workbook.saveas(path)?

the following works:

>>> xlwings import workbook >>> wb = workbook(r'c:\full\path\to\file.xlsm') >>> wb.save('new_name.xlsm') 

without specifying full name when saving, it'll (v0.3.4) save in default excel directory, should improved current python working directory in line new file.

note after saving workbook under new name, wb above still refers old file , wb.close() have no effect on new file. should improved workbook.save() returns new workbook object. i'll open issues on github page cover these improvements.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -