Fewmitz
Fewmitz

Reputation: 497

Re-compression Office Open XML files in python?

I'm writing a quick application to edit Office files using python, however I can't seem to find a good way to repack them once I'm done. OOXML is a good library but is tailored towards unzipping and exploring them, and likewise Powershell and the Open XML APIs both provide compression functions but not in Python.

I'm trying to avoid using C Types (I'd like to run this on Linux if I could) but the default zipfile module isn't acceptable to rebuild the applications with either.

Is there some library or algorithm available to general-purpose python that I"m missing?

Upvotes: 0

Views: 285

Answers (1)

Laurent LAPORTE
Laurent LAPORTE

Reputation: 22992

You can use shutil.make_archive to compress your directory:

>>> from shutil import make_archive
>>> import os
>>> archive_name = os.path.expanduser(os.path.join('~', 'myarchive'))
>>> root_dir = os.path.expanduser(os.path.join('~', '.ssh'))
>>> make_archive(archive_name, 'gztar', root_dir)
'/Users/tarek/myarchive.tar.gz'

Upvotes: 1

Related Questions