title: Python to Excel gives sharing violation
body: <p>Similar questions have been asked but none of the solutions such as using a with statement or writer.close()/writer.handles=None have solved the problem.</p>
  <p>The below code works to output my data to an excel file. Everything is fine with it except if I try to edit the file and save it while Python is still open it gives me a &quot;Sharing Violation&quot; error. Python must still be accessing it in the background but I cant figure out how to close it completely. Any suggestions?</p>
  <pre class="lang-py prettyprint-override"><code>writer = pd.ExcelWriter(output_file, engine='openpyxl', mode='a')
  
  book = openpyxl.load_workbook(output_file)
  
  writer.book = book
  outputfile(writer, book, final_data, list_name[i], False, False, &quot;C1&quot;, 2, &quot;C&quot;, 16, 30, 12, &quot;A&quot;,&quot;B&quot;)
  
  outputfile(writer, book, df_transposed, sheetposed, True, False, &quot;B2&quot;,1, &quot;B&quot;, 20, 10, 10, &quot;A&quot;,&quot;A&quot;)
          
  writer.save()
  
  writer.close
  
  writer.handles = None
  </code></pre>