def simpledoc(noimagecopy=False): """Make a docx (document, relationships) for use in other docx tests""" relationships = relationshiplist() imagefiledict = {} document = newdocument() docbody = document.xpath('/w:document/w:body', namespaces=nsprefixes)[0] docbody.append(heading('Heading 1', 1)) docbody.append(heading('Heading 2', 2)) docbody.append(paragraph('Paragraph 1')) for point in ['List Item 1', 'List Item 2', 'List Item 3']: docbody.append(paragraph(point, style='ListNumber')) docbody.append(pagebreak(type='page')) docbody.append(paragraph('Paragraph 2')) docbody.append( table([['A1', 'A2', 'A3'], ['B1', 'B2', 'B3'], ['C1', 'C2', 'C3']])) docbody.append(pagebreak(type='section', orient='portrait')) if noimagecopy: relationships, picpara, imagefiledict = picture( relationships, IMAGE1_FILE, 'This is a test description', imagefiledict=imagefiledict) else: relationships, picpara = picture(relationships, IMAGE1_FILE, 'This is a test description') docbody.append(picpara) docbody.append(pagebreak(type='section', orient='landscape')) docbody.append(paragraph('Paragraph 3')) if noimagecopy: return (document, docbody, relationships, imagefiledict) else: return (document, docbody, relationships)
def visit_image(self, node): dprint() uri = node.attributes['uri'] file_path = os.path.join(self.builder.env.srcdir, uri) dc = self.docx_container dc.relationships, picpara = docx.picture( dc.relationships, file_path, '') self.docbody.append(picpara)
def create_header(self): """ Create the header information """ # Add logo self.relationships, picpara = docx.picture(self.relationships, 'curoseven_630x158.png', 'logo') self.body.append(picpara) self.body.append(docx.heading("Bespoke Blood Analysis", 1)) self.body.append(docx.heading("Report & Recommendation", 1))
def picture(self, path, title="", pixelwidth=None, pixelheight=None): global inkscape_path _, ext = os.path.splitext(path.lower()) if ext in (".svg", '.svgz', '.eps', '.pdf'): emf_path = path.replace(ext, '.emf') args = [inkscape_path, path, '--export-emf=%s' % emf_path] returncode, stdout, stderr = pexec(args) if returncode != 0 or not os.path.exists(emf_path): inkscape_path = "" raise ConversionError("%s\n%s" % (stdout, stderr)) #succeded path = emf_path self.relationships, picpara = picture(self.relationships, path, title, pixelwidth, pixelheight) return picpara
Table_Basic.append([]) for j in range(n+1): Table_Basic[i].append("") for i in range(1,n+1): Table_Basic[0][i] = "x"+str(i) Table_Basic[i][0] = "x"+str(i) for i in range(1,n+1): for j in range(1, n+1): Table_Basic[i][j]=str(A[i-1][j-1]) docbody.append(table(Table_Basic,False,borders={'all':{'color':'auto','space':1,'sz':1}})) docbody.append(heading(u'Решение:',2)) docbody.append(paragraph(u'Согласно отношениям смежности, изобразим граф:')) # Insert an image of graph relationships,picpara = picture(relationships,'graph.png','',200,200) docbody.append(picpara) docbody.append(heading(u'1. Количество вершин n = %i'%(n),2)) docbody.append(heading(u'2. Количество ребер r = %i'%(r),2)) f = 2-n+r docbody.append(heading(u'3. Количество граней f = %i'%(f),2)) docbody.append(paragraph('n-r+f = 2')) docbody.append(paragraph('f = 2-n+r = 2-6+11 = 7')) """ ## Some examples of working with docx module ## TODO: Remove examples after finishing work
docbody.append(dx.paragraph('Tables are just lists of lists, like this:')) # Append a table docbody.append( dx.table([['A1', 'A2', 'A3'], ['B1', 'B2', 'B3'], ['C1', 'C2', 'C3']])) docbody.append(dx.heading('Editing documents', 2)) docbody.append( dx.paragraph('Thanks to the awesomeness of the lxml module, we can:')) for point in [ 'Search and replace', 'Extract plain text of document', 'Add and delete items anywhere within the document' ]: docbody.append(dx.paragraph(point, style='ListBullet')) # Add an image relationships, picpara = dx.picture(relationships, 'image1.png', 'This is a test description') docbody.append(picpara) docbody.append( dx.paragraph([ ('hello', {}), ('2', { 'vertAlign': 'superscript' }), ])) # Append a table with special properties and cells spec_cell = dx.paragraph([('2', {'vertAlign': 'superscript'})]) t_prop_margin = dx.makeelement('tblCellMar') for margin_type in ['top', 'left', 'right', 'bottom']: t_prop_margin.append(
docbody.append(dx.paragraph(point,style='ListBullet')) docbody.append(dx.paragraph('Tables are just lists of lists, like this:')) # Append a table docbody.append(dx.table([['A1','A2','A3'],['B1','B2','B3'],['C1','C2','C3']])) docbody.append(dx.heading('Editing documents',2)) docbody.append(dx.paragraph('Thanks to the awesomeness of the lxml module, we can:')) for point in ['Search and replace', 'Extract plain text of document', 'Add and delete items anywhere within the document']: docbody.append(dx.paragraph(point, style='ListBullet')) # Add an image relationships, picpara = dx.picture( relationships, 'image1.png', 'This is a test description') docbody.append(picpara) docbody.append(dx.paragraph([ ('hello', {}), ('2', {'vertAlign': 'superscript'}), ])) # Append a table with special properties and cells spec_cell = dx.paragraph([('2', {'vertAlign': 'superscript'})]) t_prop_margin = dx.makeelement('tblCellMar') for margin_type in ['top', 'left', 'right', 'bottom']: t_prop_margin.append(dx.makeelement(margin_type, attributes={'w': '0', 'type': 'dxa'})) CELL_SIZE = 12*30 # twenties of a point docbody.append(dx.table([['A1',
def simpledoc(noimagecopy=False): """Make a docx (document, relationships) for use in other docx tests""" relationships = relationshiplist() imagefiledict = {} document = newdocument() docbody = document.xpath("/w:document/w:body", namespaces=nsprefixes)[0] docbody.append(heading("Heading 1", 1)) docbody.append(heading("Heading 2", 2)) docbody.append(paragraph("Paragraph 1")) for point in ["List Item 1", "List Item 2", "List Item 3"]: docbody.append(paragraph(point, style="ListNumber")) docbody.append(pagebreak(type="page")) docbody.append(paragraph("Paragraph 2")) docbody.append(table([["A1", "A2", "A3"], ["B1", "B2", "B3"], ["C1", "C2", "C3"]])) docbody.append(pagebreak(type="section", orient="portrait")) if noimagecopy: relationships, picpara, imagefiledict = picture( relationships, IMAGE1_FILE, "This is a test description", imagefiledict=imagefiledict ) else: relationships, picpara = picture(relationships, IMAGE1_FILE, "This is a test description") docbody.append(picpara) docbody.append(pagebreak(type="section", orient="landscape")) docbody.append(paragraph("Paragraph 3")) if noimagecopy: return (document, docbody, relationships, imagefiledict) else: return (document, docbody, relationships)