Bugzilla – Attachment 74742 Details for
Bug 60771
DOCX broken (reversed) change tracking (with a tool to restore the original change tracking of the main text)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Python 3 program to remove change tracking from endnotes to fix broken docx files
fixdocx.py (text/x-python), 1.14 KB, created by
László Németh
on 2013-02-13 10:45:06 UTC
(
hide
)
Description:
Python 3 program to remove change tracking from endnotes to fix broken docx files
Filename:
MIME Type:
Creator:
László Németh
Created:
2013-02-13 10:45:06 UTC
Size:
1.14 KB
patch
obsolete
>import sys, os, zipfile, tempfile, shutil, re > ># based on the code snippet of noslio (http://stackoverflow.com/questions/4653768/overwriting-file-in-ziparchive) >def remove_from_zip(zipfname, zipnewfname, *filenames): > tempdir = tempfile.mkdtemp() > back = "" > try: > tempname = os.path.join(tempdir, 'new.zip') > with zipfile.ZipFile(zipfname, 'r') as zipread: > with zipfile.ZipFile(tempname, 'w') as zipwrite: > for item in zipread.infolist(): > data = zipread.read(item.filename) > if item.filename not in filenames: > zipwrite.writestr(item, data) > else: > back = data > shutil.move(tempname, zipnewfname) > finally: > shutil.rmtree(tempdir) > return back > >if len(sys.argv) < 3: > print("Usage: python3 fixdocx.py your.docx fixed.docx") > sys.exit() > >text = remove_from_zip(sys.argv[1], sys.argv[2], 'word/endnotes.xml') >z = zipfile.ZipFile(sys.argv[2], mode='a', compression = zipfile.ZIP_DEFLATED) >z.writestr("word/endnotes.xml", re.sub("<w:(del|ins) .*?</w:(del|ins)>", "", text.decode('utf-8')))
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 60771
:
74729
|
74730
|
74731
|
74732
|
74733
|
74734
| 74742