def __init__(self):
        # Create a new document.
        doc = Document()

        # Creates and adds a paragraph node to the document.
        para = Paragraph(doc)

        # Typed access to the last section of the document.
        section = doc.getLastSection()
        section.getBody().appendChild(para)

        # Next print the node type of one of the nodes in the document.
        nodeType = doc.getFirstSection().getBody().getNodeType()

        print "NodeType: " + Node.nodeTypeToString(nodeType)
    def __init__(self):
        # Create a new document.
        doc = Document()

        # Creates and adds a paragraph node to the document.
        para = Paragraph(doc)

        # Typed access to the last section of the document.
        section = doc.getLastSection()
        section.getBody().appendChild(para)

        # Next print the node type of one of the nodes in the document.
        nodeType = doc.getFirstSection().getBody().getNodeType()

        print "NodeType: " + Node.nodeTypeToString(nodeType)
    def different_page_setup(self):
        """
            Shows how to append a document to another document continuously which has different page settings.
        """
        
        dstDoc = Document(self.dataDir + "TestFile.Destination.doc")
        srcDoc = Document(self.dataDir + "TestFile.Source.doc")

        # Set the source document to continue straight after the end of the destination document.
        # If some page setup settings are different then this may not work and the source document will appear
        # on a new page.
        srcDoc.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS)

        # To ensure this does not happen when the source document has different page setup settings make sure the
        # settings are identical between the last section of the destination document.
        # If there are further continuous sections that follow on in the source document then this will need to be
        # repeated for those sections as well.
        srcDoc.getFirstSection().getPageSetup().setPageWidth(dstDoc.getLastSection().getPageSetup().getPageWidth())
        srcDoc.getFirstSection().getPageSetup().setPageHeight(dstDoc.getLastSection().getPageSetup().getPageHeight())
        srcDoc.getFirstSection().getPageSetup().setOrientation(dstDoc.getLastSection().getPageSetup().getOrientation())

        dstDoc.appendDocument(srcDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING)
        
        dstDoc.save(self.dataDir + "TestFile.DifferentPageSetup Out.doc")
예제 #4
0
    def copy_bookmarked_text(self):

        # Load the source document.
        srcDoc = Document(self.dataDir + "Template.doc")
        # This is the bookmark whose content we want to copy.
        srcBookmark = srcDoc.getRange().getBookmarks().get("ntf010145060")
        # We will be adding to this document.
        dstDoc = Document()
        # Let's say we will be appending to the end of the body of the last section.
        dstNode = dstDoc.getLastSection().getBody()
        # It is a good idea to use this import context object because multiple nodes are being imported.
        # If you import multiple times without a single context, it will result in many styles created.
        importer = NodeImporter(srcDoc, dstDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING)
        # Do it once.
        self.append_bookmarked_text(importer, srcBookmark, dstNode)
        # Do it one more time for fun.
        self.append_bookmarked_text(importer, srcBookmark, dstNode)
        # Save the finished document.
        dstDoc.save(self.dataDir + "Template Out.doc")
예제 #5
0
    def copy_bookmarked_text(self):

        # Load the source document.
        srcDoc = Document(self.dataDir + "Template.doc")
        # This is the bookmark whose content we want to copy.
        srcBookmark = srcDoc.getRange().getBookmarks().get("ntf010145060")
        # We will be adding to this document.
        dstDoc = Document()
        # Let's say we will be appending to the end of the body of the last section.
        dstNode = dstDoc.getLastSection().getBody()
        # It is a good idea to use this import context object because multiple nodes are being imported.
        # If you import multiple times without a single context, it will result in many styles created.
        importer = NodeImporter(srcDoc, dstDoc,
                                ImportFormatMode.KEEP_SOURCE_FORMATTING)
        # Do it once.
        self.append_bookmarked_text(importer, srcBookmark, dstNode)
        # Do it one more time for fun.
        self.append_bookmarked_text(importer, srcBookmark, dstNode)
        # Save the finished document.
        dstDoc.save(self.dataDir + "Template Out.doc")