excel - C4D python openpyxl cannot save .xlsm, but raises TypeError in zipfile.py -
this first post, , i've been searching diligently answer, please bear me!
i want able modify existing .xslm file fill motion data i've extracted within cinema-4d via python.
i did try keep_vba=true
suggested here, still got error described below. macro-enable workbook excel 2013, functioning macro wrote. working code is:
import os openpyxl import load_workbook homedir = os.path.expanduser('~') openname = 'timing_chart.xlsm' openpath = os.path.dirname(__file__) + "\\" + openname savename = raw_input('please enter save name: ') savepath = homedir+'\\desktop\\'+savename+'.xlsm' wb = load_workbook(openpath, keep_vba = true) ws = wb.active ws['b10'].value = 'loader' #just test ws['d10'].value = 25 wb.save(savepath)
when run code via enthought canopy environment (python 2.7.6 64-bit) works expected--fantastic. when try run same code in same python version used in cinema-4d installation (python 2.6.4 64-bit) works until wb.save()
command. whole pile of errors:
traceback (most recent call last): file "<pyshell#14>", line 1, in <module> wb.save(savepath) file "c:\python26\lib\site-packages\openpyxl-2.3.2-py2.6.egg\openpyxl\workbook\workbook.py", line 263, in save save_workbook(self, filename) file "c:\python26\lib\site-packages\openpyxl-2.3.2-py2.6.egg\openpyxl\writer\excel.py", line 239, in save_workbook writer.save(filename, as_template=as_template) file "c:\python26\lib\site-packages\openpyxl-2.3.2-py2.6.egg\openpyxl\writer\excel.py", line 222, in save self.write_data(archive, as_template=as_template) file "c:\python26\lib\site-packages\openpyxl-2.3.2-py2.6.egg\openpyxl\writer\excel.py", line 68, in write_data archive.writestr(arc_root_rels, write_root_rels(self.workbook)) file "c:\python26\lib\site-packages\openpyxl-2.3.2-py2.6.egg\openpyxl\writer\workbook.py", line 88, in write_root_rels arc = fromstring(workbook.vba_archive.read(arc_root_rels)) file "c:\python26\lib\zipfile.py", line 831, in read return self.open(name, "r", pwd).read() file "c:\python26\lib\zipfile.py", line 594, in read bytes = self.fileobj.read(bytestoread) typeerror: integer argument expected, got 'long'
it wasn't until writing post (and testing out statements go along make sure i'm saying accurate), discovered difference between working/failing python v2.7.6 in enthought canopy vs. python v2.6.4 in windows , cinema-4d.
originally thought specific c4d, since c4d running python 2.6.4 well, i'm hopeful can narrowed down fixable issue python version... or learn sure it's impossible python 2.6.4.
any help/advice appreciated!
okay, did not realize difference in python version have effect... little more digging in arena revealed openpyxl stopped supporting python 2.5 after version 1.7. i'm assuming similar happened python 2.6 between openpyxl 1.8 current 2.4.
i installed openpyxl v1.8.6 c4d python 2.6.4 library location (along setuptools-0.9.6-py2.6, because didn't openpyxl-1.8.6-py2.6.egg otherwise) , modified 1 line of code in c4d. update, code worked in c4d python v2.6.4 install charm!
import os openpyxl import load_workbook homedir = os.path.expanduser('~') openname = 'timing_chart.xlsm' openpath = os.path.dirname(__file__) + "\\" + openname savename = raw_input('please enter save name: ') savepath = homedir+'\\desktop\\'+savename+'.xlsm' wb = load_workbook(openpath, keep_vba = true) ws = wb.active ws['b10'].value = 'loader' #just test ws['d10'].value = 25 wb.save(savepath)
when writing values cells of new .xlsm file, openpyxl v.2.4 had line:
ws.cell(column = curcol, row = currow, value = eachkey)
which had changed to:
ws.cell(column = curcol, row = currow).value = eachkey
i hope can in future!
Comments
Post a Comment