def save(self, filename): """Save ZipFile as Excel file copy with content changed.""" o = ZipFile(filename, mode='w', compression=ZIP_DEFLATED, compresslevel=ZIP_COMPRESSION_LEVEL) i = self.root.stream zpp = self.zipparts for comp_name in zpp.keys(): content = None zc = zpp[comp_name] open_name = comp_name if zc.deleted: # Skip adding this file to the target Excel file continue if zc.name is not None: # Name of file is changing open_name = tools.renamed(open_name, zc.name) if zc.changed: content = zc.obj.content() assert (comp_name == zc.obj.filename) cin = None else: cin = i.open(comp_name) cout = o.open(open_name, mode='w', force_zip64=True) if content is not None: cout.write(content) else: cout.write(cin.read()) # FIXME: Do it with finite size buffer cout.close() if cin is not None: cin.close() o.close()
def tablename_changed(self, filename, name): ofn = "/" + filename node = self.ovr[ofn] new_name = tools.renamed(node.attrib["PartName"], name) del self.ovr[ofn] node.attrib["PartName"] = new_name self.ovr[new_name] = node self.invalidate()
def name(self, value): # FIXME: We can rename table only onece ctx = self.context ctx.load() ctx.state.name = value old_fn = ctx.filename ctx.filename = tools.renamed(old_fn, value) ctx.xldoc.tablename_changed(old_fn, value)
def tablename_changed(self, filename, name): for k, rel in self.ids.items(): if filename.endswith(rel.target): # FIXME: Bad supposition break else: raise ValueError('object not found') rel.element.attrib['Target'] = tools.renamed(rel.target, name) self.invalidate()
def tablename_changed(self, filename, name): self.rels.tablename_changed(filename, name) self.root.root.contentType.tablename_changed(filename, name) root = self.root.root zpp = root.zipparts new_fn = tools.renamed(filename, name) fs = zpp[filename] assert (fs.obj is not None) del zpp[filename] zpp[new_fn] = fs fs.changed = True