document.insert_style(style) # The paragraph text = (u'The office document file format OpenDocument Format (ODF) ' u'is an ISO standard ISO 26300 used by many applications.') paragraph = odf_create_paragraph(text, u"Standard") paragraph.set_span(u"style2", regex=u"ISO standard") body.append(paragraph) # 6- A variable # ------------- # A variable "spam" with the value 42 variable_set = odf_create_variable_set('spam', 42) value_type = variable_set.get_attribute('office:value-type') variable_decl = odf_create_variable_decl('spam', value_type) # Insert heading = odf_create_heading(1, text=u'A variable') body.append(heading) decl = body.get_variable_decls() decl.append(variable_decl) text = u'Set of spam.' paragraph = odf_create_paragraph(text, style=u"Standard") body.append(paragraph) paragraph._insert_between(variable_set, u"Set", u"spam.") text = u'The value of spam is: ' value = body.get_variable_set_value('spam')
def test_create_variable_decl(self): variable_decl = odf_create_variable_decl(u'你好 Zoé', 'float') expected = ('<text:variable-decl office:value-type="float" ' 'text:name="%s"/>') % convert_unicode(u'你好 Zoé') self.assertEqual(variable_decl.serialize(), expected)
# The paragraph text = (u'The office document file format OpenDocument Format (ODF) ' u'is an ISO standard ISO 26300 used by many applications.') paragraph = odf_create_paragraph(text, u"Standard") paragraph.set_span(u"style2", regex=u"ISO standard") body.append(paragraph) # 4- A variable # ------------- # A variable "spam" with the value 42 variable_set = odf_create_variable_set('spam', 42) value_type = variable_set.get_attribute('office:value-type') variable_decl = odf_create_variable_decl('spam', value_type) # Insert heading = odf_create_heading(1, text=u'A variable') body.append(heading) decl = body.get_variable_decls() decl.append(variable_decl) text = u'Set of spam.' paragraph = odf_create_paragraph(text, style=u"Standard") body.append(paragraph) paragraph._insert_between(variable_set, u"Set", u"spam.") text = u'The value of spam is: ' value = body.get_variable_set_value('spam')
def test_create_variable_decl(self): variable_decl = odf_create_variable_decl('你好 Zoé', 'float') expected = ('<text:variable-decl office:value-type="float" ' 'text:name="%s"/>') % convert_unicode('你好 Zoé') self.assertEqual(variable_decl.serialize(), expected)