title: Embed CSV in Excel and import the data
body: <p>I wrote a tool that extracts data from a large DB and outputs it to an Excel file along with (conditional) formatting to improve readability. For this I use Python with <code>openpyxl</code> on a Linux machine. It works great, but this package is rather slow for writing Excel.</p>
  
  <p>It seems to be a lot quicker to dump the table as (compressed) csv, import that into Excel and apply formatting there using a macro/vba.</p>
  
  <p>To automate the process I'd like to create an empty Excel file pre-loaded with the required VBA to do the formatting; a template. For every data dump, the data is embedded (compressed using deflate) into the Excel file and loaded into the Workbook upon opening the document (or using a "LOAD" button to circumvent macro related security things).</p>
  
  <p>However, just adding some file into the Excel file raises an error when opened: </p>
  
  <blockquote>
    <p>We found a problem with some content in 'Werkmap1_test_embed.xlsx'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.</p>
  </blockquote>
  
  <p>Clicking <code>Yes</code> opens the file and shows some tracing information as XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"&gt;
    &lt;logFileName&gt;Repair Result to Werkmap1_OLE_Word0.xml&lt;/logFileName&gt;
    &lt;summary&gt;Errors were detected in file '/Users/joostk/mnt/cluster/Werkmap1_OLE_Word.xlsx'&lt;/summary&gt;
    &lt;additionalInfo&gt;
        &lt;info&gt;Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.&lt;/info&gt;
    &lt;/additionalInfo&gt;
  &lt;/recoveryLog&gt;
  </code></pre>
  
  <p>Is it possible to avoid this? How would I embed a file into the Excel ZIP? Do I need to update some file table (which I could not file easily).</p>
  
  <p>When that's done, I'd like to import the data. Can I access files in the Excel ZIP from VBA? I guess not, and I need to extract the data to some temporary path and load it from there. </p>
  
  <p>I have found these helpful answers elsewhere to load ZIP and plain text: </p>
  
  <ul>
  <li><a href="https://stackoverflow.com/a/35781621/4998990">https://stackoverflow.com/a/35781621/4998990</a></li>
  <li><a href="https://stackoverflow.com/a/11267603/4998990">https://stackoverflow.com/a/11267603/4998990</a></li>
  </ul>
  
  <p>Many thanks for sharing your thoughts!</p>