コード例 #1
0
def testsearchandreplace():
    """Ensure search and replace functions work"""
    document, docbody, relationships = simpledoc()
    docbody = document.xpath('/w:document/w:body', namespaces=nsprefixes)[0]
    assert search(docbody, 'ing 1')
    assert search(docbody, 'ing 2')
    assert search(docbody, 'graph 3')
    assert search(docbody, 'ist Item')
    assert search(docbody, 'A1')
    if search(docbody, 'Paragraph 2'):
        docbody = replace(docbody, 'Paragraph 2', 'Whacko 55')
    assert search(docbody, 'Whacko 55')
コード例 #2
0
ファイル: test_docx.py プロジェクト: bighome/python-docx-1
def testsearchandreplace():
    """Ensure search and replace functions work"""
    document, docbody, relationships = simpledoc()
    docbody = document.xpath("/w:document/w:body", namespaces=nsprefixes)[0]
    assert search(docbody, "ing 1")
    assert search(docbody, "ing 2")
    assert search(docbody, "graph 3")
    assert search(docbody, "ist Item")
    assert search(docbody, "A1")
    if search(docbody, "Paragraph 2"):
        docbody = replace(docbody, "Paragraph 2", "Whacko 55")
    assert search(docbody, "Whacko 55")
コード例 #3
0
    # Search and replace
    print 'Searching for something in a paragraph ...',
    if dx.search(docbody, 'the awesomeness'):
        print 'found it!'
    else:
        print 'nope.'

    print 'Searching for something in a heading ...',
    if dx.search(docbody, '200 lines'):
        print 'found it!'
    else:
        print 'nope.'

    print 'Replacing ...',
    docbody = dx.replace(docbody, 'the awesomeness',
                         'the goshdarned awesomeness')
    print 'done.'

    # Add a pagebreak
    docbody.append(dx.pagebreak(type='page', orient='portrait'))

    docbody.append(dx.heading('Ideas? Questions? Want to contribute?', 2))
    docbody.append(dx.paragraph('''Email <*****@*****.**>'''))

    # Create our properties, contenttypes, and other support files
    coreprops = dx.coreproperties(
        title='Python docx demo',
        subject='A practical example of making docx from Python',
        creator='Mike MacCana',
        keywords=['python', 'Office Open XML', 'Word'])
    appprops = dx.appproperties()
コード例 #4
0
    
    # Search and replace
    print 'Searching for something in a paragraph ...',
    if dx.search(docbody, 'the awesomeness'):
         print 'found it!'
    else:
         print 'nope.'
         
    print 'Searching for something in a heading ...',
    if dx.search(docbody, '200 lines'):
         print 'found it!'
    else:
         print 'nope.'
    
    print 'Replacing ...',
    docbody = dx.replace(docbody,'the awesomeness','the goshdarned awesomeness') 
    print 'done.'

    # Add a pagebreak
    docbody.append(dx.pagebreak(type='page', orient='portrait'))

    docbody.append(dx.heading('Ideas? Questions? Want to contribute?',2))
    docbody.append(dx.paragraph('''Email <*****@*****.**>'''))

    # Create our properties, contenttypes, and other support files
    coreprops = dx.coreproperties(
        title='Python docx demo',
        subject='A practical example of making docx from Python',
        creator='Mike MacCana',
        keywords=['python','Office Open XML','Word'])
    appprops = dx.appproperties()