title: Python pandas write resulted dataframe to xlsm without losing the macro
body: <p>I have a lot of excel files that I need to compile into a single excel file, and then copy the compiled one into an existing excel file (with macro / .xlsm) in a certain sheet.</p>
  
  <p>I solved the first problem (compiling multiple excel files into a single excel file). The resulted dataframe is saved in .csv format. The resulted file looks like this.
  <a href="https://i.stack.imgur.com/q1gdi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q1gdi.png" alt="the resulted dataframe"></a></p>
  
  <p>Until here there is no issue. The next step that I am struggling to find out how to do it.</p>
  
  <p>From the resulted dataframe I want to "copy-and-paste" the dataframe to the existing excel file with macro (.xlsm) in the sheet "Source" at the corresponding headers. The existing excel file looks like this.
  <a href="https://i.stack.imgur.com/utC0b.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/utC0b.jpg" alt="target excel file"></a></p>
  
  <p>As you may see from the picture above, I want to skip writing any data in the column A since the cells within this column is full of formula. I want to write the resulted dataframe in the column B to column Q within the existing excel file. However, before writing the data, I want delete all the existing data in all cells (except in the cells within column A).</p>
  
  <p>So basically I want to do the following:</p>
  
  <ol>
  <li>delete all the values in the cells in the column B to column Q in
  the existing xlsm file (in the sheet "Source")</li>
  <li>write the new values from the resulted dataframe to column B until column Q</li>
  <li>save the excel file back with the same name without losing the macro</li>
  </ol>
  
  <p>Any feedback will be much appreciated! Thanks!</p>
  
  <p>Regards,</p>
  
  <p>Arnold</p>