Using openpyxl to copy from one workbook to another results in error when saving
<p>I am trying to append the values from one sheet row by row to a new workbook. My code works when I run it on a small test file, but when I run it on my target file it returns an error when saving.</p>

<p>Here is my code:</p>

<pre><code>from openpyxl import load_workbook
from openpyxl import Workbook

wb = load_workbook(filename='RM Activity-Pricing Report - 2014-05-31.xlsm',keep_vba=False, data_only=True)
ws_Ottawa = wb.get_sheet_by_name('Ottawa')

wb2 = Workbook()
ws2 = wb2.create_sheet()

for row in ws_Ottawa.iter_rows():
        ws2.append(row)

wb2.save('new_big_file.xlsx')
</code></pre>

<p>The output error I get in Spyder (python 3.5) is:</p>

<pre><code>Traceback (most recent call last):

File "&lt;ipython-input-22-171ffbcd4891&gt;", line 1, in &lt;module&gt;
runfile('Z:/Revenue Management Report/ExtractPromoData.py', wdir='Z:/Revenue Management Report')

File "C:\Anaconda3-64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
execfile(filename, namespace)

File "C:\Anaconda3-64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 88, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)

File "Z:/Revenue Management Report/ExtractPromoData.py", line 35, in &lt;module&gt;
wb2.save('new_big_file4.xlsx')

File "C:\Anaconda3-64\lib\site-packages\openpyxl\workbook\workbook.py", line 298, in save
save_workbook(self, filename)

File "C:\Anaconda3-64\lib\site-packages\openpyxl\writer\excel.py", line 198, in save_workbook
writer.save(filename, as_template=as_template)

File "C:\Anaconda3-64\lib\site-packages\openpyxl\writer\excel.py", line 181, in save
self.write_data(archive, as_template=as_template)

File "C:\Anaconda3-64\lib\site-packages\openpyxl\writer\excel.py", line 87, in write_data
self._write_worksheets(archive)

File "C:\Anaconda3-64\lib\site-packages\openpyxl\writer\excel.py", line 114, in _write_worksheets
write_worksheet(sheet, self.workbook.shared_strings,

File "C:\Anaconda3-64\lib\site-packages\openpyxl\writer\worksheet.py", line 233, in write_worksheet
write_rows(xf, worksheet)

File "C:\Anaconda3-64\lib\site-packages\openpyxl\writer\lxml_worksheet.py", line 59, in write_rows
if cell.value is None and not cell.has_style:

File "C:\Anaconda3-64\lib\site-packages\openpyxl\cell\cell.py", line 306, in value
if value is not None and self.is_date:

File "C:\Anaconda3-64\lib\site-packages\openpyxl\cell\cell.py", line 351, in is_date
if self.data_type == "n" and self.number_format != "General":

File "C:\Anaconda3-64\lib\site-packages\openpyxl\styles\styleable.py", line 49, in __get__
return coll[idx - 164]
IndexError: list index out of range
</code></pre>

<p>I do not get an error when I use my code on a smaller test .xlsx file.</p>

<p>Possible reasons for the problem that I suspect are:</p>

<p>1)input file is .xlsm</p>

<p>2)input file is has columns from A to CI</p>

<p>3)input file is password protected (but since the error is in saving this does not seem like it should be an issue)</p>

<p>Taking into account what Charlie said, this is my work-around
  from openpyxl import load_workbook
    from openpyxl import Workbook</p>

<pre><code> wb = load_workbook(filename='RM Activity-Pricing Report - 2014-5-31.xlsm',keep_vba=False, data_only=True)#,guess_types=True)


ws_Ottawa = wb.get_sheet_by_name('Ottawa')

wb2 = Workbook()
ws2 = wb2.create_sheet()
counter = 0
new_rows = []
for rrow in ws_Ottawa.iter_rows():
    new_rows.append([])
    for cell in rrow:
        new_rows[counter].append(cell.value)
    counter +=1
for wrow in new_rows:

    ws2.append(wrow)

wb2.save('new_big_file4.xlsx')


print("ALL DONE")
</code></pre>