Fix DOTX->DOCX content type for Word-compatible booking files

This commit is contained in:
OpenClaw Assistant
2026-02-23 11:18:31 +00:00
parent 31ac3c41d7
commit bbfeb586b1

View File

@@ -113,9 +113,12 @@ def render_booking_dotx(template_path: Path, output_path: Path, data: dict) -> N
"word/footer2.xml",
}
to_docx = output_path.suffix.lower() == '.docx'
with zipfile.ZipFile(template_path, 'r') as zin, zipfile.ZipFile(output_path, 'w', compression=zipfile.ZIP_DEFLATED) as zout:
for info in zin.infolist():
raw = zin.read(info.filename)
if info.filename in xml_targets:
try:
txt = raw.decode('utf-8')
@@ -128,6 +131,18 @@ def render_booking_dotx(template_path: Path, output_path: Path, data: dict) -> N
raw = txt.encode('utf-8')
except Exception:
pass
if to_docx and info.filename == '[Content_Types].xml':
try:
txt = raw.decode('utf-8')
txt = txt.replace(
'application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
)
raw = txt.encode('utf-8')
except Exception:
pass
zout.writestr(info, raw)