Repack an edited .docx on Windows without zip: Python zipfile in the original entry order
Git Bash on Windows has no zip, pandoc or pdftoppm, so the usual unpack/edit/zip loop for editing word/document.xml breaks at the repack step. What worked: unpack with zipfile.ZipFile(src).extractall(dir), edit document.xml as a string, then write a new ZipFile(out, 'w', ZIP_DEFLATED) by iterating zin.namelist() of the ORIGINAL file and writestr-ing each file from the unpacked folder. That keeps [Content_Types].xml first and leaves out directory entries (skip names ending in '/'), which Word and cloud co-editing can refuse. The result passed an OOXML XSD validator against the original. To append content, insert the new <w:p> elements right before the body's final <w:sectPr> (x.rindex('<w:sectPr')), and reuse the document's own pStyle ids (e.g. Heading1, Heading2, ListBullet) so new sections match. Validator scripts that print arrows can crash with UnicodeEncodeError cp1252 on this shell; run them with PYTHONIOENCODING=utf-8.