Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Walk template dir for zip creation

- Further preliminary work on image creation
  • Loading branch information...
commit d05c229d95e3006ca476f11decc75c189f204ed1 1 parent ce52fed
@mikemaccana authored
View
2  HACKING.markdown
@@ -3,7 +3,7 @@ Adding Features
# Recommended reading
-- The LXML tutorial at http://codespeak.net/lxml/tutorial.html covers the basics of XML etrees, which we create append and insert to make XML documents
+- The LXML tutorial at http://codespeak.net/lxml/tutorial.html covers the basics of XML etrees, which we create, append and insert to make XML documents. LXML also provides XPath, which we use to specify locations in the document.
- The OpenXML WordML specs and videos at http://openxmldeveloper.org (if you're stuck)
- Learning about XML namespaces http://www.w3schools.com/XML/xml_namespaces.asp
- The Namespaces section of http://diveintopython3.org/xml.html
View
2  LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2009 Mike MacCana
+Copyright (c) 2009-2010 Mike MacCana
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
View
57 docx.py
@@ -10,6 +10,7 @@
import zipfile
import re
import time
+import os
# All Word prefixes / namespace matches used in document.xml & core.xml
# LXML doesn't actually use prefixes (just the real namespace) , but these
@@ -248,32 +249,9 @@ def picture():
inline.append(graphic)
drawing = makeelement('drawing')
drawing.append(inline)
+ drawing = etree.fromstring('''<w:drawing xmlns:w='{http://schemas.openxmlformats.org/wordprocessingml/2006/main}'/>''')
return drawing
- '''
- <w:drawing>
- <wp:inline distT="0" distB="0" distL="0" distR="0">
- <wp:extent cx="5486400" cy="3429000"/>
- <wp:effectExtent l="25400" t="0" r="0" b="0"/>
- <wp:docPr id="1" name="Picture 0" descr="aero_glow_v2_1920x1200.png"/>
- <wp:cNvGraphicFramePr>
- <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/>
- <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
- <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
- <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
- <pic:nvPicPr>
- <pic:cNvPr id="0" name="aero_glow_v2_1920x1200.png"/>
- <pic:cNvPicPr/>
- <pic:blipFill>
- <a:blip r:embed="rId5"/>
- <a:stretch>
- <a:fillRect/>
- <pic:spPr>
- <a:xfrm>
- <a:off x="0" y="0"/>
- <a:ext cx="5486400" cy="3429000"/>
- <a:prstGeom prst="rect">
- <a:avLst/>
- '''
+
def search(document,search):
@@ -354,32 +332,21 @@ def docproperties(title,subject,creator,keywords,lastmodifiedby=None):
-def savedocx(document,properties,newfilename):
+def savedocx(document,properties,docxfilename):
'''Save a modified document'''
- newfile = zipfile.ZipFile(newfilename,mode='w')
+ docxfile = zipfile.ZipFile(docxfilename,mode='w')
# Write our generated document
documentstring = etree.tostring(document, pretty_print=True)
- newfile.writestr('word/document.xml',documentstring)
+ docxfile.writestr('word/document.xml',documentstring)
# And it's properties
propertiesstring = etree.tostring(properties, pretty_print=True)
- newfile.writestr('docProps/core.xml',propertiesstring)
+ docxfile.writestr('docProps/core.xml',propertiesstring)
# Add support files
- for xmlfile in [
- '[Content_Types].xml',
- '_rels/.rels',
- 'docProps/thumbnail.jpeg',
- 'docProps/app.xml',
- 'word/webSettings.xml',
- 'word/_rels/document.xml.rels',
- 'word/styles.xml',
- 'word/numbering.xml',
- 'word/theme/',
- 'word/theme/theme1.xml',
- #'word/media/image1.png',
- 'word/settings.xml',
- 'word/fontTable.xml']:
- newfile.write('template/'+xmlfile,xmlfile)
- print 'Saved new file to: '+newfilename
+ for dirpath,dirnames,filenames in os.walk('template'):
+ for filename in filenames:
+ templatefile = os.path.join(dirpath,filename)
+ docxfile.write(templatefile,templatefile.replace('template',''))
+ print 'Saved new file to: '+docxfilename
return
View
2  template/word/_rels/document.xml.rels
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings" Target="webSettings.xml"/><Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image1.png"/><Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/><Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Target="fontTable.xml"/></Relationships>
+<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/><Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings" Target="webSettings.xml"/><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/><Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Target="fontTable.xml"/></Relationships>
View
7 template/word/document.xml
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<w:document xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main" xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
-xmlns:v="urn:schemas-microsoft-com:vml"
-xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" ve:Ignorable="mv" ve:PreserveAttributes="mv:*">
- <w:body>
- </w:body>
-</w:document>
Please sign in to comment.
Something went wrong with that request. Please try again.