title: Python (openpyxl) : Put data from one excel file to another (template file) & save it with another name while retaining the template
body: <p>I have a <strong><em>template</em></strong> excel file named as <code>template.xlsx</code> which has a number of sheets. I would like to copy data from a seperate <code>.csv</code> file into the first sheet of <code>template.xlsx</code> (named as <strong><code>data</code></strong>) and save the new file as <strong><code>result.xlsx</code></strong> while retaining the original template file.</p>
  
  <p>I want to paste the data starting from the second row in the <strong><code>data</code></strong> sheet of <code>template.xlsx</code> </p>
  
  <p>This is the code I have developed so far</p>
  
  <pre><code>import pandas as pd
  from openpyxl.utils.dataframe import dataframe_to_rows
  import openpyxl
  from shutil import copyfile
  
  template_file = 'template.xlsx' # Has a header in row 1 already which needs to be skipped while pasting data but it should be there in the output file
  output_file = 'result.xlsx' 
  
  copyfile(template_file, output_file)
  df = pd.read_csv('input_file.csv') #The file which is to be pasted in the template
  
  wb = openpyxl.load_workbook(output_file)
  ws = wb.get_sheet_by_name('data') #Getting the sheet named as 'data'
  
  for r in dataframe_to_rows(df, index=False, header=False):
     ws.append(r)
  
   wb.save(output_file)
  </code></pre>
  
  <p>I am not able to get the desired output</p>
  
  <p>The template file (with an extra row) on the left and the input file (data to be copied to the template) on the right, look like this </p>
  
  <p><a href="https://i.stack.imgur.com/XBYHC.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/XBYHC.jpg" alt="template"></a> <a href="https://i.stack.imgur.com/oQbTr.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/oQbTr.jpg" alt="enter image description here"></a></p>