def __init__(self): dataDir = Settings.dataDir + 'programming_documents/' doc = Document() builder = DocumentBuilder(doc) # Insert few page breaks (just for testing) i = 0 while (i < 5): builder.insertBreak(BreakType.PAGE_BREAK) i = i + 1 # Move DocumentBuilder cursor into the primary footer. builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY) # We want to insert a field like this: # { IF {PAGE} <> {NUMPAGES} "See Next Page" "Last Page" } field = builder.insertField("IF ") builder.moveTo(field.getSeparator()) builder.insertField("PAGE") builder.write(" <> ") builder.insertField("NUMPAGES") builder.write(" \"See Next Page\" \"Last Page\" ") # Finally update the outer field to recalcaluate the final value. Doing this will automatically update # the inner fields at the same time. field.update() doc.save(dataDir + "InsertNestedFields Out.docx")
def __init__(self): dataDir = Settings.dataDir + 'programming_documents/' doc = Document() builder = DocumentBuilder(doc) # Insert few page breaks (just for testing) i = 0 while(i < 5): builder.insertBreak(BreakType.PAGE_BREAK) i = i + 1 # Move DocumentBuilder cursor into the primary footer. builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY) # We want to insert a field like this: # { IF {PAGE} <> {NUMPAGES} "See Next Page" "Last Page" } field = builder.insertField("IF ") builder.moveTo(field.getSeparator()) builder.insertField("PAGE") builder.write(" <> ") builder.insertField("NUMPAGES") builder.write(" \"See Next Page\" \"Last Page\" ") # Finally update the outer field to recalcaluate the final value. Doing this will automatically update # the inner fields at the same time. field.update() doc.save(dataDir + "InsertNestedFields Out.docx")
def __init__(self): dataDir = Settings.dataDir + 'programming_documents/' doc = Document(dataDir + "document.doc") builder = DocumentBuilder(doc) #Shows how to access the current node in a document builder. curNode = builder.getCurrentNode() curParagraph = builder.getCurrentParagraph() # Shows how to move a cursor position to a specified node. builder.moveTo(doc.getFirstSection().getBody().getLastParagraph()) # Shows how to move a cursor position to the beginning or end of a document. builder.moveToDocumentEnd() builder.writeln("This is the end of the document.") builder.moveToDocumentStart() builder.writeln("This is the beginning of the document.") doc.save(dataDir + "MovingCursor.doc") print "Done."