Beispiel #1
0
 def _xml(self):
     appprops = make_element('Properties',nsprefix='ep')
     appprops = etree.fromstring(
     '''<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
     <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"></Properties>''')
     props = {
             'Template':'Normal.dotm',
             'TotalTime':'6',
             'Pages':'1',  
             'Words':'83',   
             'Characters':'475', 
             'Application':self.application,
             'DocSecurity':'0',
             'Lines':'12', 
             'Paragraphs':'8',
             'ScaleCrop':'false', 
             'LinksUpToDate':'false', 
             'CharactersWithSpaces':'583',  
             'SharedDoc':'false',
             'HyperlinksChanged':'false',
             'AppVersion':self.version,
             }
     for prop in props:
         appprops.append(make_element(prop,tagtext=props[prop],nsprefix=None))
     return appprops
Beispiel #2
0
 def _xml(self):
     content_types = etree.fromstring('''<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
     <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"></Types>''')
     for t in self.types:
         content_types.append(
             make_element('Override',nsprefix=None,attributes={'PartName':t,'ContentType':self.types[t]})
         )
     # Add support for filetypes
     filetypes = {
         'rels':'application/vnd.openxmlformats-package.relationships+xml',
         'xml':'application/xml',
         'jpeg':'image/jpeg',
         'gif':'image/gif',
         'png':'image/png',
         'wmf': 'image/x-wmf',
     }
     for extension in filetypes:
         content_types.append(
             make_element(
                 'Default',
                 nsprefix=None,
                 attributes={
                     'Extension':extension,
                     'ContentType':filetypes[extension]
                 }
             )
         )
     return content_types
Beispiel #3
0
 def __init__(self, template_file=None, template_dir=None):
     self.template_file = template_file
     self.template_dir = template_dir
     if self.template_file and os.path.isfile(self.template_file):
         self._init_from_file(self.template_file)
     else:
         self.template_file = None
         self.document = make_element("document")
         self.body = make_element("body")
         self.document.append(self.body)
         self.app_properties = AppProperties()
         self.core_properties = None
         self.word_relationships = WordRelationships()
         self.web_settings = WebSettings()
         self.content_types = ContentTypes()
Beispiel #4
0
 def _xml(self):
     '''Generate a Word relationships file'''
     # FIXME: using string hack instead of making element
     relationships = etree.fromstring(
     '''<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
     <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
         </Relationships>'''
     )
     for relationship in self.relationshiplist:
         relationships.append(make_element('Relationship',attributes={'Id': relationship[0],
         'Type':relationship[1],'Target':relationship[2]},nsprefix=None))
     return relationships
Beispiel #5
0
 def _xml(self):
     coreprops = make_element('coreProperties',nsprefix='cp')    
     coreprops.append(make_element('title', tagtext=self.title, nsprefix='dc'))
     coreprops.append(make_element('subject', tagtext=self.subject, nsprefix='dc'))
     coreprops.append(make_element('creator', tagtext=self.creator, nsprefix='dc'))
     coreprops.append(make_element('keywords', tagtext=','.join(self.keywords), nsprefix='cp'))    
     coreprops.append(make_element('lastModifiedBy', tagtext=self.lastmodifiedby, nsprefix='cp'))
     coreprops.append(make_element('revision', tagtext='1', nsprefix='cp'))
     coreprops.append(make_element('category', tagtext='Examples', nsprefix='cp'))
     coreprops.append(make_element('description', tagtext='Examples', nsprefix='dc'))
     currenttime = time.strftime('%Y-%m-%dT%H:%M:%SZ')
     # Document creation and modify times
     # Prob here: we have an attribute who name uses one namespace, and that 
     # attribute's value uses another namespace.
     # We're creating the lement from a string as a workaround...
     for doctime in ['created','modified']:
         coreprops.append(etree.fromstring('''<dcterms:'''+doctime+''' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dcterms="http://purl.org/dc/terms/" xsi:type="dcterms:W3CDTF">'''+currenttime+'''</dcterms:'''+doctime+'''>'''))
         pass
     return coreprops
Beispiel #6
0
 def __init__(self, file, template=None):
     self.container=zipfile.ZipFile(file, "w")
     self._add_template(template if template is not None else TEMPLATE_DIR)
     self.document=make_element("document")
     self.body=make_element("body")
     self.document.append(self.body)
Beispiel #7
0
 def _xml(self):
     web = make_element('webSettings')
     web.append(make_element('allowPNG'))
     web.append(make_element('doNotSaveAsSingleFile'))
     return web