当前位置: 首页>>代码示例>>Python>>正文


Python opendocument.OpenDocumentText类代码示例

本文整理汇总了Python中odf.opendocument.OpenDocumentText的典型用法代码示例。如果您正苦于以下问题:Python OpenDocumentText类的具体用法?Python OpenDocumentText怎么用?Python OpenDocumentText使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OpenDocumentText类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_style

 def test_style(self):
     """ Get an automatic style with getStyleByName """
     textdoc = OpenDocumentText()
     boldstyle = style.Style(name=u'Bold', family=u"text")
     boldstyle.addElement(style.TextProperties(fontweight=u"bold"))
     textdoc.automaticstyles.addElement(boldstyle)
     s = textdoc.getStyleByName(u'Bold')
     self.assertEqual((u'urn:oasis:names:tc:opendocument:xmlns:style:1.0', 'style'), s.qname)
开发者ID:abiapp,项目名称:odfpy,代码行数:8,代码来源:teststyles.py

示例2: test_headings

 def test_headings(self):
     textdoc = OpenDocumentText()
     textdoc.text.addElement(H(outlinelevel=1, text="Heading 1"))
     textdoc.text.addElement(P(text="Hello World!"))
     textdoc.text.addElement(H(outlinelevel=2, text="Heading 2"))
     textdoc.save("TEST.odt")
     self.saved = True
     result = odf2moinmoin.ODF2MoinMoin("TEST.odt")
     self.assertEquals(u'= Heading 1 =\n\nHello World!\n== Heading 2 ==\n\n', result.toString())
开发者ID:BrickXu,项目名称:odfpy,代码行数:9,代码来源:testmoinmoin.py

示例3: test_linebreak

 def test_linebreak(self):
     textdoc = OpenDocumentText()
     p = P(text="Hello World!")
     textdoc.text.addElement(p)
     p.addElement(LineBreak())
     p.addText("Line 2")
     textdoc.save("TEST.odt")
     self.saved = True
     result = odf2moinmoin.ODF2MoinMoin("TEST.odt")
     self.assertEquals(u'Hello World![[BR]]Line 2\n', result.toString())
开发者ID:BrickXu,项目名称:odfpy,代码行数:10,代码来源:testmoinmoin.py

示例4: testAddPicture

 def testAddPicture(self):
     """ Check that AddPicture works"""
     THUMBNAILNAME = "thumbnail.png"
     icon = thumbnail.thumbnail()
     f = open(THUMBNAILNAME, "wb")
     f.write(icon)
     f.close()
     textdoc = OpenDocumentText()
     textdoc.addPicture(THUMBNAILNAME)
     os.unlink(THUMBNAILNAME)
开发者ID:aq1,项目名称:odfpy,代码行数:10,代码来源:testpicture.py

示例5: exportODT

def exportODT(examen, archivo):
    """ 
    Function to export the data exam to a odt file.
    The input data is the exam and the ODT file to write.
    This function uses odfpy library
    """
    
    # Extract data from exam
    asignatura = examen.asignatura
    nombre = examen.nombre
    preguntas = examen.preguntas

    textdoc = OpenDocumentText()
      
    h = H(outlinelevel=1, text=asignatura)
    textdoc.text.addElement(h)
    
    h = H(outlinelevel=4, text=nombre)
    textdoc.text.addElement(h)
    
    # an element is added to the object "textdoc" for each question
    i = 1
    for pregunta in preguntas:
        texto = str(i) + ".- " + pregunta.texto
        p = P(text = texto)
        textdoc.text.addElement(p)
   
        # For test questions
        if pregunta.tipo == 1:
            for opcion in pregunta.opciones:
                texto = opcion.letra + ") " + opcion.texto
                p = P(text = texto)
                textdoc.text.addElement(p)
                                        
        # For true or false questions
        elif pregunta.tipo == 2:
            texto = "A) Verdadero"
            p = P(text = texto.encode('utf-8'))
            textdoc.text.addElement(p)
            
            texto = "B) Falso"
            p = P(text = texto)
            textdoc.text.addElement(p)
            
        p = P()
        textdoc.text.addElement(p)
        p = P()
        textdoc.text.addElement(p)

        i = i + 1
        
    # Save complete file
    textdoc.save(archivo)
        
    return examen
开发者ID:luisferperez,项目名称:Educaweb,代码行数:55,代码来源:export.py

示例6: test_headings

 def test_headings(self):
     """ Create a document, save it and load it """
     textdoc = OpenDocumentText()
     textdoc.text.addElement(H(outlinelevel=1, text=u"Heading 1"))
     textdoc.text.addElement(P(text=u"Hello World!"))
     textdoc.text.addElement(H(outlinelevel=2, text=u"Heading 2"))
     textdoc.save(u"TEST.odt")
     self.saved = True
     d = load(u"TEST.odt")
     result = d.contentxml() # contentxml() is supposed to yeld a bytes
     self.assertNotEqual(-1, result.find(b"""<text:h text:outline-level="1">Heading 1</text:h><text:p>Hello World!</text:p><text:h text:outline-level="2">Heading 2</text:h>"""))
开发者ID:abiapp,项目名称:odfpy,代码行数:11,代码来源:testload.py

示例7: Document_Generic

class Document_Generic(object):
    """Example of document"""
    def __init__(self):
        self.document = OpenDocumentText()
        self.defineStyles()

    def defineStyles(self):
        """  """
        pass

    def addParagraphStyle(self, id, name, paragraph_properties={}, text_properties={}):
        """  """
        style = Style(name=name, family="paragraph")
        if len(paragraph_properties) > 0:
            style.addElement(ParagraphProperties(**paragraph_properties))
        if len(text_properties) > 0:
            style.addElement(TextProperties(**text_properties))
        setattr(self, id, style)
        self.document.styles.addElement(style)

    def addTableColumnStyle(self, id, name, properties={}):
        """  """
        style = Style(name=name, family="table-column")
        style.addElement(TableColumnProperties(**properties))
        setattr(self, id, style)
        self.document.automaticstyles.addElement(style)

    def addParagraph(self, text, stylename):
        """  """
        stylename = getattr(self, stylename, None)
        p = P(stylename=stylename, text=text)
        self.document.text.addElement(p)

    def addTable(self, content, cell_style, column_styles=[]):
        """  """
        cell_style = getattr(self, cell_style, None)
        table = Table()
        for style in column_styles:
            if "stylename" in style.keys():
                style["stylename"] = getattr(self, style["stylename"], None)
                table.addElement(TableColumn(**style))
        for row in content:
            tr = TableRow()
            table.addElement(tr)
            for cell in row:
                tc = TableCell()
                tr.addElement(tc)
                p = P(stylename=cell_style,text=cell)
                tc.addElement(p)
        self.document.text.addElement(table)

    def save(self, filename):
        """  """
        self.document.save(filename)
开发者ID:Guts,项目名称:Metadator,代码行数:54,代码来源:test_md2odt_old.py

示例8: test_linebreak

 def test_linebreak(self):
     """ Test that a line break (empty) element show correctly """
     textdoc = OpenDocumentText()
     p = P(text=u"Hello World!")
     textdoc.text.addElement(p)
     p.addElement(LineBreak())
     p.addText(u"Line 2")
     textdoc.save(u"TEST.odt")
     self.saved = True
     d = load(u"TEST.odt")
     result = d.contentxml() # contentxml() is supposed to yeld a bytes
     self.assertNotEqual(-1, result.find(b"""<text:p>Hello World!<text:line-break/>Line 2</text:p>"""))
开发者ID:abiapp,项目名称:odfpy,代码行数:12,代码来源:testload.py

示例9: testAttributeForeign

 def testAttributeForeign(self):
     """ Test that you can add foreign attributes """
     textdoc = OpenDocumentText()
     standard = style.Style(name="Standard", family="paragraph")
     p = style.ParagraphProperties(qattributes={(u'http://foreignuri.com',u'enable-numbering'):'true'})
     standard.addElement(p)
     textdoc.styles.addElement(standard)
     s = unicode(textdoc.stylesxml(),'UTF-8')
     s.index(u"""<?xml version='1.0' encoding='UTF-8'?>\n""")
     s.index(u'xmlns:ns30="http://foreignuri.com"')
     s.index(u'<style:paragraph-properties ns30:enable-numbering="true"/>')
     s.index(u'<office:styles><style:style style:name="Standard" style:display-name="Standard" style:family="paragraph">')
开发者ID:agiacomolli,项目名称:odfpy,代码行数:12,代码来源:teststyles.py

示例10: TestUnicode

class TestUnicode(unittest.TestCase):
    def setUp(self):
        self.textdoc = OpenDocumentText()
        self.saved = False

    def tearDown(self):
        if self.saved:
            os.unlink("TEST.odt")

    def test_subobject(self):
        df = draw.Frame(width="476pt", height="404pt", anchortype="paragraph")
        self.textdoc.text.addElement(df)

        subdoc = OpenDocumentText()
        # Here we add the subdocument to the main document. We get back a reference
        # to use in the href.
        subloc = self.textdoc.addObject(subdoc)
        self.assertEqual(subloc, "./Object 1")
        do = draw.Object(href=subloc)
        df.addElement(do)

        subsubdoc = OpenDocumentText()
        subsubloc = subdoc.addObject(subsubdoc)
        self.assertEqual(subsubloc, "./Object 1/Object 1")

        c = unicode(self.textdoc.contentxml(), "UTF-8")
        c.index(
            u'<office:body><office:text><draw:frame svg:width="476pt" text:anchor-type="paragraph" svg:height="404pt"><draw:object xlink:href="./Object 1"/></draw:frame></office:text></office:body>'
        )
        c.index(u'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"')
        self.textdoc.save("TEST.odt")
        self.saved = True
        m = _getxmlpart("TEST.odt", "META-INF/manifest.xml")
        m.index(
            '<manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="/"/>'
        )
        m.index('<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="styles.xml"/>')
        m.index('<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="content.xml"/>')
        m.index('<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="meta.xml"/>')
        m.index(
            '<manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="Object 1/"/>'
        )
        m.index('<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="Object 1/styles.xml"/>')
        m.index('<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="Object 1/content.xml"/>')
        m.index(
            '<manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="Object 1/Object 1/"/>'
        )
        m.index(
            '<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="Object 1/Object 1/styles.xml"/>'
        )
        m.index(
            '<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="Object 1/Object 1/content.xml"/>'
        )
开发者ID:pikhovkin,项目名称:odfpy,代码行数:53,代码来源:testsubobjects.py

示例11: odt_write

def odt_write(object, filename, introduction=None, lmf2odt=lmf_to_odt, items=lambda lexical_entry: lexical_entry.get_lexeme(), sort_order=None, paradigms=False, reverse=False):
    """! @brief Write a document file.
    @param object The LMF instance to convert into document output format.
    @param filename The name of the document file to write with full path, for instance 'user/output.odt'.
    @param introduction The name of the text file with full path containing the introduction of the document, for instance 'user/config/introduction.txt'. Default value is None.
    @param lmf2odt A function giving the mapping from LMF representation information that must be written to ODT commands, in a defined order. Default value is 'lmf_to_odt' function defined in 'pylmflib/config/odt.py'. Please refer to it as an example.
    @param items Lambda function giving the item to sort. Default value is 'lambda lexical_entry: lexical_entry.get_lexeme()', which means that the items to sort are lexemes.
    @param sort_order Python list. Default value is 'None', which means that the document output is alphabetically ordered.
    @param paradigms A boolean value to introduce paradigms in document or not.
    @param reverse A boolean value to set if a reverse dictionary is wanted.
    """
    import string
    if sort_order is None:
        # Lowercase and uppercase letters must have the same rank
        sort_order = dict([(c, ord(c)) for c in string.lowercase])
        up = dict([(c, ord(c) + 32) for c in string.uppercase])
        sort_order.update(up)
        sort_order.update({'':0, ' ':0})
    textdoc = OpenDocumentText()
    # Styles
    s = textdoc.styles
    h1style = Style(name="Heading 1", family="paragraph")
    h1style.addElement(TextProperties(attributes={'fontsize':"24pt", 'fontweight':"bold" }))
    s.addElement(h1style)
    # An automatic style
    boldstyle = Style(name="Bold", family="text")
    boldprop = TextProperties(fontweight="bold", fontname="Arial", fontsize="8pt")
    boldstyle.addElement(boldprop)
    textdoc.automaticstyles.addElement(boldstyle)
    # Parse LMF values
    if object.__class__.__name__ == "LexicalResource":
        for lexicon in object.get_lexicons():
            # Document title
            h = H(outlinelevel=1, stylename=h1style, text=lexicon.get_id())
            textdoc.text.addElement(h)
            # Plain paragraph
            p = P(text=lexicon.get_label())
            # Text
            boldpart = Span(stylename=boldstyle, text="Test. ")
            p.addElement(boldpart)
            # Introduction
            if introduction is not None:
                p.addText(file_read(introduction))
                textdoc.text.addElement(p)
            # Page break
            #
            # Text body
            lmf2odt(lexicon, textdoc, items, sort_order, paradigms, reverse)
    else:
        raise OutputError(object, "Object to write must be a Lexical Resource.")
    textdoc.save(filename)
开发者ID:buret,项目名称:pylmflib,代码行数:51,代码来源:odt.py

示例12: test_write

 def test_write(self):
     """ document's write method """
     outfp = cStringIO.StringIO()
     textdoc = OpenDocumentText()
     p = P(text=u"Æblegrød")
     p.addText(u' Blåbærgrød')
     textdoc.text.addElement(p)
     textdoc.write(outfp)
     outfp.seek(0)
     # outfp now contains the document.
     z = zipfile.ZipFile(outfp,"r")
     self.assertEqual(None, z.testzip())
     
     outfp.close()
开发者ID:BrickXu,项目名称:odfpy,代码行数:14,代码来源:testwrite.py

示例13: TestUnicode

class TestUnicode(unittest.TestCase):

    def setUp(self):
        self.textdoc = OpenDocumentText()
        self.saved = False

    def tearDown(self):
        if self.saved:
            os.unlink("TEST.odt")

    def test_subobject(self):
        df = draw.Frame(width="476pt", height="404pt", anchortype="paragraph")
        self.textdoc.text.addElement(df)

        subdoc = OpenDocumentText()
        # Here we add the subdocument to the main document. We get back a reference
        # to use in the href.
        subloc = self.textdoc.addObject(subdoc)
        self.assertEqual(subloc,'./Object 1')
        do = draw.Object(href=subloc)
        df.addElement(do)

        subsubdoc = OpenDocumentText()
        subsubloc = subdoc.addObject(subsubdoc)
        self.assertEqual(subsubloc,'./Object 1/Object 1')

        c = self.textdoc.contentxml() # contentxml() is supposed to yeld a bytes
        c.index(b'<office:body><office:text><draw:frame ')
        e = ElementParser(c.decode("utf-8"), u'draw:frame')
#       e = ElementParser('<draw:frame svg:width="476pt" text:anchor-type="paragraph" svg:height="404pt">')
        self.assertTrue(e.has_value(u'svg:width',"476pt"))
        self.assertTrue(e.has_value(u'svg:height',"404pt"))
        self.assertTrue(e.has_value(u'text:anchor-type',"paragraph"))
        self.assertFalse(e.has_value(u'svg:height',"476pt"))
        c.index(b'<draw:object xlink:href="./Object 1"/></draw:frame></office:text></office:body>')
        c.index(b'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"')
        self.textdoc.save(u"TEST.odt")
        self.saved = True
        m = _getxmlpart(u"TEST.odt", u"META-INF/manifest.xml").decode('utf-8')
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="/"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="/"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="content.xml"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="meta.xml"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="Object 1/"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="Object 1/styles.xml"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="Object 1/content.xml"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="Object 1/Object 1/"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="Object 1/Object 1/styles.xml"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="Object 1/Object 1/content.xml"'))
开发者ID:eea,项目名称:odfpy,代码行数:49,代码来源:testsubobjects.py

示例14: __init__

 def __init__( self, template=None ):
     if not template:
         self.doc = OpenDocumentText()
     else:
         self.doc = load( template )
     self.cur_par = None
     self._create_styles()
开发者ID:dmishin,项目名称:aozora2odt,代码行数:7,代码来源:aozora2odt.py

示例15: testMasterWithHeader

 def testMasterWithHeader(self):
     """ Create a text document with a page layout called "pagelayout"
         Add a master page
         Check that pagelayout is listed in styles.xml
     """
     textdoc = OpenDocumentText()
     pl = style.PageLayout(name="pagelayout")
     textdoc.automaticstyles.addElement(pl)
     mp = style.MasterPage(name="Standard", pagelayoutname=pl)
     textdoc.masterstyles.addElement(mp)
     h = style.Header()
     hp = text.P(text="header try")
     h.addElement(hp)
     mp.addElement(h)
     s = unicode(textdoc.stylesxml(),'UTF-8')
     self.assertContains(s, u'<office:automatic-styles><style:page-layout style:name="pagelayout"/></office:automatic-styles>')
开发者ID:BrickXu,项目名称:odfpy,代码行数:16,代码来源:testmasterstyles.py


注:本文中的odf.opendocument.OpenDocumentText类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。