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


Python OpenDocumentText.addObject方法代码示例

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


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

示例1: TestUnicode

# 需要导入模块: from odf.opendocument import OpenDocumentText [as 别名]
# 或者: from odf.opendocument.OpenDocumentText import addObject [as 别名]
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,代码行数:55,代码来源:testsubobjects.py

示例2: TestUnicode

# 需要导入模块: from odf.opendocument import OpenDocumentText [as 别名]
# 或者: from odf.opendocument.OpenDocumentText import addObject [as 别名]
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,代码行数:51,代码来源:testsubobjects.py

示例3: test_subobject

# 需要导入模块: from odf.opendocument import OpenDocumentText [as 别名]
# 或者: from odf.opendocument.OpenDocumentText import addObject [as 别名]
    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 ')
        e = ElementParser(c, 'draw:frame')
#       e = ElementParser('<draw:frame svg:width="476pt" text:anchor-type="paragraph" svg:height="404pt">')
        self.assertTrue(e.has_value('svg:width',"476pt"))
        self.assertTrue(e.has_value('svg:height',"404pt"))
        self.assertTrue(e.has_value('text:anchor-type',"paragraph"))
        self.assertFalse(e.has_value('svg:height',"476pt"))
        c.index(u'<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:BrickXu,项目名称:odfpy,代码行数:41,代码来源:testsubobjects.py

示例4: __init__

# 需要导入模块: from odf.opendocument import OpenDocumentText [as 别名]
# 或者: from odf.opendocument.OpenDocumentText import addObject [as 别名]
class Doc:

    def __init__(self, filename, language="de", curesec_brand=True):

        # create document tree
        self.document = OpenDocumentText()

        # set members
        self.filename = filename
        self.language = language

        # some basic report details
        self.project = "XY-932521-OMEGA"
        self.date = TODAY
        self.dateStart = TODAY
        self.dateEnd = TODAY
        self.author = "Curesec GmbH"
        self.authorAddress = "Berliner Allee 170"
        self.clientName = "Name des Kunden"
        self.clientAddress = "Adresse des Kunden"
        self.version = "0.1"

        # define style and add user information
        self.__style = DocumentStyle()
        self.__style.defineCuresecStyles(self.document, self.language)

        if curesec_brand:
            self.__style.addUserfieldsToBody(self.document,
                                             projekt=self.project,
                                             date=self.date,
                                             dateStart=self.dateStart,
                                             dateEnd=self.dateEnd,
                                             author=self.author,
                                             authorAddress=self.authorAddress,
                                             clientName=self.clientName,
                                             clientAddress=self.clientAddress,
                                             version=self.version
                                             )
            self.setHeader()
            self.setFooter()
            self.setDeckblatt()
            self.setVertragspartner()
            self.setTableOfContent()

    def setTableOfContent(self):
        self.__style.addTableOfContent(self.document)

    def setDeckblatt(self):
        self.__style.addDeckblatt(self.document)

    def setVertragspartner(self):
        self.__style.addVertragspartner(self.document)

    def setFooter(self):
        self.__style.setFooterData(self.document)

    def setHeader(self):
        self.__style.setHeaderData(self.document,
                                   self.project,
                                   self.date,
                                   self.version)

    def save(self):
        # save document
        self.document.save(self.filename)

    def add(self, element):
        if element is not None:
            self.document.text.addElement(element)

    def addAsObject(self, element):
        if element is not None:
            return self.document.addObject(element)
开发者ID:yeyintminthuhtut,项目名称:recotak-framework,代码行数:75,代码来源:document.py

示例5: mychart

# 需要导入模块: from odf.opendocument import OpenDocumentText [as 别名]
# 或者: from odf.opendocument.OpenDocumentText import addObject [as 别名]
    # These represent the data. Six rows in three columns
    mychart.values = (
        ('','Expense','Revenue'),
        ('Counterfeit',1000,1500),
        ('Murder',1100,1150),
        ('Prostitution',3200,2350),
        ('Blackmail',1100,1150),
        ('Larceny',1000,1750)
    )
    mychart.datasourcehaslabels = "both"
    mychart(chartdoc)

    # Create the containg document
    textdoc = OpenDocumentText()
    # Create a paragraph to contain the frame. You can put the frame directly
    # as a child og textdoc.text, but both Kword and OOo has problems wiht
    # this approach.
    p = text.P()
    textdoc.text.addElement(p)
    # Create the frame.
    df = draw.Frame(width="476pt", height="404pt", anchortype="paragraph")
    p.addElement(df)

    # Here we add the subdocument to the main document. We get back a reference
    # to use in the href.
    objectloc = textdoc.addObject(chartdoc)
    do = draw.Object(href=objectloc)
    # Put the object inside the frame
    df.addElement(do)
    textdoc.save("spectre-balance", True)
开发者ID:BrickXu,项目名称:odfpy,代码行数:32,代码来源:subobject.py


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