title: Openpyxl's xml changes break my workbook. I need a fix or alternative
body: <p>I have a very large .xlsm that is used as a template. There are 4 blank tabs in the workbook that the rest of the workbook looks at. Those sheets are all text formatted with no other formatting needed. I have a program that:</p>
  <ul>
  <li>Executes an SQL query,</li>
  <li>Copies and renames the template based on my input,</li>
  <li>Populates those 4 tabs with my query data,(openpyxl)</li>
  <li>Saves the notebook.(openpyxl)</li>
  </ul>
  <p>I recently introduced a new version of the template, and now when I open the output file I get the following error (after telling excel it can recover the notebook.)</p>
  <blockquote>
  <p>Replaced Part: /xl/worksheets/sheet31.xml part with XML error.  The namespace for 'xmlns:xml' is reserved and it can only be declared as 'http://www.w3.org/XML/1998/namespace'. Line 8, column 90.</p>
  </blockquote>
  <p>I have found the issue in the xml for the sheet in question.</p>
  <p>If I take this line:</p>
  <pre><code>&lt;/f&gt;&lt;v&gt;&lt;/v&gt;&lt;/c&gt;&lt;c r=&quot;E2&quot; s=&quot;132&quot;&gt;&lt;f xmlns:ns0=&quot;http://www.w3.org/XML/1998/namespace&quot; aca=&quot;1&quot; ca=&quot;1&quot; ref=&quot;E2&quot; t=&quot;array&quot; ns0:space=&quot;preserve&quot;&gt;
  </code></pre>
  <p>And I update it to:</p>
  <pre><code>&lt;/f&gt;&lt;v&gt;&lt;/v&gt;&lt;/c&gt;&lt;c r=&quot;E2&quot; s=&quot;132&quot;&gt;&lt;f aca=&quot;1&quot; ca=&quot;1&quot; ref=&quot;E2&quot; t=&quot;array&quot; xml:space=&quot;preserve&quot;&gt;
  </code></pre>
  <p>...I can open it with no problem!</p>
  <p>Comparing the template's xml for that sheet to what openpyxl outputs, I am sure that it essentially rewriting the entire notebook as it best understands it is the problem. <strong>I need either an alternative that is capable of simply writing to those tabs and keeping the rest of the notebook in tact, or I need to know if there is something in the openpyxl code/commands themselves that I can change in order to avoid this.</strong></p>
  <p>It is notable that the cell that the xml is on is an array formula that targets a named range on another tab (something that exists elsewhere in the notebook), and that if I delete that formula or strip out certain pieces of it in the template that the file that is exported has no problems opening at all, but that was done for testing and no workaround I've tried for the formula is safe from the error.</p>
  <p><strong>EDIT:</strong>
  I have verified no trailing spaces in the formula, and even tried it with spaces removed in any output. The error persists.</p>
  <p>Here is the formula in the cell that the xml error will occur on:</p>
  <pre><code>{=
  SUBSTITUTE(
  SUBSTITUTE(
  SUBSTITUTE(
  SUBSTITUTE(
  IF(A2=&quot;&quot;,&quot;&quot;,IFERROR(VLOOKUP($A2&amp;&quot;|&quot;&amp;$C2,INDIRECT(&quot;'&quot;&amp;INDEX(Lookup_sheets,MATCH(1,--(COUNTIF(INDIRECT(&quot;'&quot;&amp;Lookup_sheets&amp;&quot;'!$T:$T&quot;),$A2&amp;&quot;|&quot;&amp;$C2)&gt;0),0))&amp;&quot;'!$T:$U&quot;),2,FALSE),&quot;NOT FOUND&quot;)),
  INDEX(SIMP_CONF_FIND,1),INDEX(SIMP_CONF_REP,1)),
  INDEX(SIMP_CONF_FIND,2),INDEX(SIMP_CONF_REP,2)),
  INDEX(SIMP_CONF_FIND,3),INDEX(SIMP_CONF_REP,3)),
  INDEX(SIMP_CONF_FIND,4),INDEX(SIMP_CONF_REP,4))}
  </code></pre>