def setUp(self): container = odf_get_container('samples/example.odt') self.container = container self.content_part = content_part = odf_xmlpart(ODF_CONTENT, container) self.paragraph_element = content_part.get_element('//text:p[1]') self.annotation_element = ( content_part.get_element('//office:annotation[1]'))
def test_delete(self): container = self.container content = odf_xmlpart(ODF_CONTENT, container) paragraphs = content.get_elements('//text:p') for paragraph in paragraphs: content.delete_element(paragraph) serialized = content.serialize() self.assertEqual(serialized.count('<text:p'), 0)
def test_serialize(self): container = self.container content_bytes = container.get_part(ODF_CONTENT) content_part = odf_xmlpart(ODF_CONTENT, container) # differences with lxml serialized = content_part.serialize().replace("'", "'") # XXX OOo is adding two carriage returns behind the XML declaration serialized = serialized.replace('<?xml version="1.0" encoding="UTF-8"?>\n', '<?xml version="1.0" encoding="UTF-8"?>\n\n') self.assertEqual(content_bytes, serialized)
def test_serialize(self): container = self.container content_bytes = container.get_part(ODF_CONTENT) content_part = odf_xmlpart(ODF_CONTENT, container) # differences with lxml serialized = content_part.serialize().replace("'", "'") # XXX OOo is adding two carriage returns behind the XML declaration serialized = serialized.replace( '<?xml version="1.0" encoding="UTF-8"?>\n', '<?xml version="1.0" encoding="UTF-8"?>\n\n') self.assertEqual(content_bytes, serialized)
def test_add_chart_structure_in_document(self): doc = odf_new_document('spreadsheet') name = add_chart_structure_in_document(doc) chart_content = odf_xmlpart(name + '/content.xml', doc) expected = ( '<?xml version="1.0" encoding="UTF-8"?>\n' '<office:document-content ' 'xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" ' 'xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" ' 'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" ' 'xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" ' 'xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" ' 'xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" ' 'xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" ' 'xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" ' 'xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" ' 'xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" ' 'xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" ' 'xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" ' 'xmlns:math="http://www.w3.org/1998/Math/MathML" ' 'xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" ' 'xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" ' 'xmlns:ooo="http://openoffice.org/2004/office" ' 'xmlns:ooow="http://openoffice.org/2004/writer" ' 'xmlns:oooc="http://openoffice.org/2004/calc" ' 'xmlns:dom="http://www.w3.org/2001/xml-events" ' 'xmlns:xforms="http://www.w3.org/2002/xforms" ' 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' 'xmlns:rpt="http://openoffice.org/2005/report" ' 'xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" ' 'xmlns:xhtml="http://www.w3.org/1999/xhtml" ' 'xmlns:grddl="http://www.w3.org/2003/g/data-view#" ' 'xmlns:tableooo="http://openoffice.org/2009/table" ' 'xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" ' 'xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" ' 'office:version="1.2" ' 'grddl:transformation="http://docs.oasis-open.org/office/1.2/xslt/odf2rdf.xsl">\n\n ' '<office:automatic-styles/>\n ' '<office:body>\n ' '<office:chart/>\n ' '</office:body>\n' '</office:document-content>') self.assertEqual(chart_content.serialize(), expected)
def test_add_chart_structure_in_document(self): doc = odf_new_document('spreadsheet') name = add_chart_structure_in_document(doc) chart_content = odf_xmlpart(name+'/content.xml', doc) expected =( '<?xml version="1.0" encoding="UTF-8"?>\n' '<office:document-content ' 'xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" ' 'xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" ' 'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" ' 'xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" ' 'xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" ' 'xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" ' 'xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" ' 'xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" ' 'xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" ' 'xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" ' 'xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" ' 'xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" ' 'xmlns:math="http://www.w3.org/1998/Math/MathML" ' 'xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" ' 'xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" ' 'xmlns:ooo="http://openoffice.org/2004/office" ' 'xmlns:ooow="http://openoffice.org/2004/writer" ' 'xmlns:oooc="http://openoffice.org/2004/calc" ' 'xmlns:dom="http://www.w3.org/2001/xml-events" ' 'xmlns:xforms="http://www.w3.org/2002/xforms" ' 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' 'xmlns:rpt="http://openoffice.org/2005/report" ' 'xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" ' 'xmlns:xhtml="http://www.w3.org/1999/xhtml" ' 'xmlns:grddl="http://www.w3.org/2003/g/data-view#" ' 'xmlns:tableooo="http://openoffice.org/2009/table" ' 'xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" ' 'xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" ' 'office:version="1.2" ' 'grddl:transformation="http://docs.oasis-open.org/office/1.2/xslt/odf2rdf.xsl">\n\n ' '<office:automatic-styles/>\n ' '<office:body>\n ' '<office:chart/>\n ' '</office:body>\n' '</office:document-content>') self.assertEqual(chart_content.serialize(), expected)
def setUp(self): container = odf_get_container("samples/example.odt") self.container = container content_part = odf_xmlpart("content", container) self.paragraph_element = content_part.get_element("//text:p[1]")
def setUp(self): self.container = odf_get_container("samples/span_style.odt") self.content = odf_xmlpart("content", self.container) self.paragraph = self.content.get_element("//text:p") self.span = self.paragraph.get_element("//text:span")
def setUp(self): self.container = odf_get_container('samples/span_style.odt') self.content = odf_xmlpart(ODF_CONTENT, self.container) self.paragraph = self.content.get_element('//text:p') self.span = self.paragraph.get_element('//text:span')
def test_root(self): content = odf_xmlpart(ODF_CONTENT, self.container) root = content.get_root() self.assert_(isinstance(root, odf_element)) self.assertEqual(root.get_tag(), "office:document-content") self.assertNotEqual(content._odf_xmlpart__root, None)
def test_tree(self): # Testing a private but important method content = odf_xmlpart(ODF_CONTENT, self.container) tree = content._odf_xmlpart__get_tree() self.assert_(isinstance(tree, _ElementTree)) self.assertNotEqual(content._odf_xmlpart__tree, None)
def test_get_element_list(self): content_part = odf_xmlpart(ODF_CONTENT, self.container) elements = content_part.get_elements('//text:p') # The annotation paragraph is counted self.assertEqual(len(elements), 8)
def setUp(self): self.container = container = odf_get_container('samples/example.odt') self.content_part = content_part = odf_xmlpart(ODF_CONTENT, container) self.paragraph_element = content_part.get_element('//text:p[1]') query = '//style:style[@style:family="paragraph"][1]' self.style_element = content_part.get_element(query)
### #Third step : create our chart ### table = odf_create_table('Gantt') body.append(table) cell_range="Data.A1:Data."+_digit_to_alpha(len(result))+str(len(result[0])) cols_list = divide_range(cell_range) #we add the xml files that will contain the chart informations chart_directory = add_chart_structure_in_document(document) #we need an access to the office:automatic-styles element chart_content = odf_xmlpart(chart_directory+'/content.xml', document) styles = chart_content.get_element("office:automatic-styles") #we add informations about style styles.append(odf_create_chart_title_style("titre", "12pt")) plot_s = odf_create_chart_plot_area_style("plot") plot_s.set_vertical("true") plot_s.set_stacked("true") styles.append(plot_s) axe_x_style = odf_create_chart_axis_style("axe x") styles.append(axe_x_style) axe_y_style = odf_create_chart_axis_style("axe y") axe_y_style.set_properties({'chart:minimum': '0'}, area='chart') styles.append(axe_y_style)