def function():
    #获得参数
    # SimulationTime_get = str(inp1.get())
    # dt_get = str(inp2.get())
    # compressed_get = str(inp3.get())
    constraints_get = str(comb.get())
    rcoulomb_get = str(inp5.get())
    rvdw_get = str(inp5.get())
    tc_get = str(inp7.get())
    tau_get = str(inp8.get())
    ref_get = str(inp9.get())
    gen_temp_get = str(inp10.get())
    #作一步计算
    #加载模板
    template = "./model/NVTmdp.docx"

    document = MailMerge(template)
    print("Fields included in {}: {}".format(template, document.get_merge_fields()))
    document.merge(
        constraints=constraints_get,         #这个要看模型
        rcoulomb=rcoulomb_get,            #这个为cutoff 参数值。rvdw是LJ或buckingham的阈值。默认为1.0 nm
        rvdw=rvdw_get,                #这个为cutoff 参数值。rvdw是LJ或buckingham的阈值。默认为1.0 nm
        tc_grps=tc_get,             #这个是温度热浴的分组
        tau_t=tau_get,               #只是增加或减少组别数
        ref_t=ref_get,               #这个是改温度的。单位是开氏温度K。(分组要对应好,tau_t有两个0.1就是两个组,ref_t也要两个组。)
        gen_temp=gen_temp_get       #这个温度要于ref_t对应
    )
    document.write('NVT-MdpOut.docx')
    path = "NVT-MdpOut.docx"
    doc = Document(path)
    print("----------生成模板中-----------")
    #批量写入到mdp中
    with open("NVT-MdpOut.mdp", "w") as file:
        for paragraph in doc.paragraphs:
            print(paragraph.text)
            file.write(paragraph.text + "\n")
    #别嘴臭我,我真的只会if和else........
    # answer = tkinter.messagebox.askokcancel('消息', '模板文件生成成功')
    # if nsteps_get == '':
    #     answer = tkinter.messagebox.askokcancel('警告', 'nsteps没有填写')
    # if dt_get == '':
    #     answer = tkinter.messagebox.askokcancel('警告', 'dt没有填写')
    # if compressed_get == '':
    #     answer = tkinter.messagebox.askokcancel('警告', 'compressed没有填写')
    if constraints_get == '':
        answer = tkinter.messagebox.askokcancel('警告', 'constraints没有填写')
    if rcoulomb_get == '':
        answer = tkinter.messagebox.askokcancel('警告', 'rcoulomb没有填写')
    if rvdw_get == '':
        answer = tkinter.messagebox.askokcancel('警告', 'rvdw没有填写')
    if tc_get == '':
        answer = tkinter.messagebox.askokcancel('警告', 'tc-grps没有填写')
    if tau_get == '':
        answer = tkinter.messagebox.askokcancel('警告', 'tau-t没有填写')
    if ref_get == '':
        answer = tkinter.messagebox.askokcancel('警告', 'ref-t没有填写')
    if gen_temp_get == '':
        answer = tkinter.messagebox.askokcancel('警告', 'gen_temp没有填写')
    else:
        answer = tkinter.messagebox.askokcancel('消息', '模板文件生成成功')
    def test(self):
        document = MailMerge(
            path.join(path.dirname(__file__), 'test_macword2011.docx'))
        self.assertEqual(
            document.get_merge_fields(),
            set([
                'first_name', 'last_name', 'country', 'state', 'postal_code',
                'date', 'address_line', 'city'
            ]))

        document.merge(first_name='Bouke',
                       last_name='Haarsma',
                       country='The Netherlands',
                       state=None,
                       postal_code='9723 ZA',
                       city='Groningen',
                       address_line='Helperpark 278d',
                       date='May 22nd, 2013')

        with tempfile.TemporaryFile() as outfile:
            document.write(outfile)

        expected_tree = etree.fromstring(
            '<w:document xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" '
            'xmlns:ns1="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w="http://schemas'
            '.openxmlformats.org/wordprocessingml/2006/main" mc:Ignorable="w14 wp14">'
            '<w:body><w:p ns1:paraId="25CDEC86" ns1:textId="77777777" '
            'w:rsidR="00FB567A" w:rsidRDefault="00541684"><w:r><w:t>Bouke</w:t></w:r><w:r w:rsidR="00916690"><w:t '
            'xml:space="preserve"> </w:t></w:r><w:r><w:t>Haarsma</w:t></w:r></w:p><w:p ns1:paraId="67F7A559" '
            'ns1:textId="77777777" w:rsidR="00916690" w:rsidRDefault="00541684"><w:r><w:t>Helperpark '
            '278d</w:t></w:r></w:p><w:p ns1:paraId="228F2AEA" ns1:textId="77777777" w:rsidR="00916690" '
            'w:rsidRDefault="00541684"><w:r><w:t>9723 ZA</w:t></w:r><w:r><w:t xml:space="preserve"> '
            '</w:t></w:r><w:r><w:t>Groningen</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd '
            'w:id="0" /><w:r w:rsidR="00916690"><w:t xml:space="preserve"> </w:t></w:r><w:r><w:t /></w:r><w:r '
            'w:rsidR="00916690"><w:t xml:space="preserve"> </w:t></w:r><w:r><w:t>The '
            'Netherlands</w:t></w:r></w:p><w:p ns1:paraId="696E15D7" ns1:textId="77777777" w:rsidR="00916690" '
            'w:rsidRDefault="00916690" /><w:p ns1:paraId="3F48DA35" ns1:textId="77777777" w:rsidR="00916690" '
            'w:rsidRDefault="00916690" /><w:p ns1:paraId="68E7FBD1" ns1:textId="77777777" w:rsidR="00916690" '
            'w:rsidRDefault="00916690"><w:r><w:t xml:space="preserve">Groningen, </w:t></w:r><w:r><w:t>May 22nd, '
            '2013</w:t></w:r><w:r><w:t>,</w:t></w:r></w:p><w:p ns1:paraId="26B47597" ns1:textId="77777777" '
            'w:rsidR="00916690" w:rsidRDefault="00916690" /><w:p ns1:paraId="740FF493" ns1:textId="77777777" '
            'w:rsidR="00916690" w:rsidRDefault="00916690" /><w:p ns1:paraId="232699A0" ns1:textId="77777777" '
            'w:rsidR="00916690" w:rsidRDefault="00916690"><w:r><w:t xml:space="preserve">Dear '
            '</w:t></w:r><w:r><w:t>Bouke</w:t></w:r><w:r><w:t>,</w:t></w:r></w:p><w:p ns1:paraId="1AE04A19" '
            'ns1:textId="77777777" w:rsidR="00916690" w:rsidRDefault="00916690" /><w:p ns1:paraId="298752B0" '
            'ns1:textId="77777777" w:rsidR="00916690" w:rsidRDefault="00916690" /><w:p ns1:paraId="477BE6DB" '
            'ns1:textId="77777777" w:rsidR="00916690" w:rsidRDefault="00916690"><w:r><w:t>I hope this message finds '
            'you well.</w:t></w:r></w:p><w:p ns1:paraId="77542CE2" ns1:textId="77777777" w:rsidR="00916690" '
            'w:rsidRDefault="00916690" /><w:p ns1:paraId="734AC552" ns1:textId="77777777" w:rsidR="00916690" '
            'w:rsidRDefault="00916690" /><w:p ns1:paraId="1680D84C" ns1:textId="77777777" w:rsidR="00916690" '
            'w:rsidRDefault="00916690"><w:r><w:t>Kind regards,</w:t></w:r></w:p><w:p ns1:paraId="67F698AC" '
            'ns1:textId="77777777" w:rsidR="00916690" w:rsidRDefault="00916690" /><w:p ns1:paraId="7A4C001B" '
            'ns1:textId="77777777" w:rsidR="00916690" w:rsidRDefault="00916690"><w:r><w:t>docx-mailmerge'
            '.</w:t></w:r></w:p><w:sectPr w:rsidR="00916690" w:rsidSect="00CA5A66"><w:pgSz w:h="16840" w:w="11900" '
            '/><w:pgMar w:bottom="1417" w:footer="708" w:gutter="0" w:header="708" w:left="1417" w:right="1417" '
            'w:top="1417" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body></w:document>'
        )

        self.assert_equal_tree(expected_tree,
                               list(document.parts.values())[0].getroot())
Example #3
0
    def mail_merge(self, template, kwargs):

        company_name = kwargs.get('Company_Name', "default company_name")
        print('******',company_name)
        print('*******************', kwargs.items())
        document = MailMerge(template)
        print (document.get_merge_fields())
        #merge fields
        #{'ZIP_Code', 'Address_Line_2', 'Country_or_Region',
        #'Address_Line_1', 'Company_Name', 'Title',
        # 'State', 'City', 'First_Name', 'Work_Phone',
        #'Email_Address', 'Home_Phone', 'Last_Name'}

        document.merge(Title=kwargs.get('Title', "default title"),
                First_Name=kwargs.get('First_Name', "default fname"),
                Last_Name=kwargs.get('Last_Name', "default lname"),
            Company_Name=kwargs.get('Company_Name', "default company_name"),
                Email_Address=kwargs.get('Email_Address', "default email"),
                City=kwargs.get('City', "default city"),
                State=kwargs.get('State', "default state"),
                Work_Phone=kwargs.get('Work_Phone', "default Work Phone"),
                Address_Line_1=kwargs.get('Address_Line_1', "Address_Line_1"),
        Address_Line_2=kwargs.get('Address_Line_2', "default Address_Line_2"),
                Home_Phone=kwargs.get('Home_Phone', "Home_Phone"),
Country_or_Region=kwargs.get('Country_or_Region', "default Country_or_Region"),
                    ZIP_Code=kwargs.get('ZIP_Code ', "default ZIP_Code "))

        output = company_name + '_output.docx'
        document.write(output)
        print(output, ' is ready')
        return  output
Example #4
0
def add_template():
    form = AddDocx()
    target = current_app.config['MERGE_TEMPLATES_FOLDER']
    if not os.path.exists(target): os.makedirs(target)
    if form.validate_on_submit():
        file = form.file.data
        name = form.name.data
        file_name = secure_filename(current_user.username.lower() + '_' +
                                    uuid.uuid4().hex + '.docx')
        file_path = os.path.join(target, file_name)
        file.save(file_path)
        print('File saved: {}'.format(file_name))
        new_template = TemplateDocx(file_path=file_path,
                                    name=name,
                                    description=form.description.data,
                                    file_size=os.path.getsize(file_path),
                                    user_id=current_user.id,
                                    timestamp=datetime.utcnow(),
                                    latest_use=datetime.utcnow(),
                                    docs_generated=0)
        db.session.add(new_template)
        db.session.commit()
        doc = MailMerge(file_path)
        fields = doc.get_merge_fields()
        for field in fields:
            new_f = MergeField(label=field.lower().strip(),
                               template=new_template.id)
            db.session.add(new_f)
            db.session.commit()
            print('Added <{}> field for template: {}'.format(field, name))
        flash(
            'Template {} added. Detected {} merge fields'.format(
                name, len(fields)), 'info')
        return redirect(url_for('mailmerge.mailmerge'))
    return render_template('mailmerge/add_docx.html', form=form)
Example #5
0
    def test_pages_with_multiple_pages(self):
        """
        This also tests that merge_pages produces a multiple paged document,
        however this template already contains two pages. So the result should
        be 3 * 2 pages.
        """
        document = MailMerge(
            path.join(path.dirname(__file__), 'test_merge_pages_paged.docx'))
        self.assertEqual(document.get_merge_fields(), {'fieldname'})

        document.merge_pages([
            {
                'fieldname': "xyz"
            },
            {
                'fieldname': "abc"
            },
            {
                'fieldname': "2b v ~2b"
            },
        ])

        with tempfile.TemporaryFile() as outfile:
            document.write(outfile)

        expected_tree = ElementTree.fromstring(
            '<w:document xmlns:ns1="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p w:rsidP="007B2B98" w:rsidR="00507D2F" w:rsidRDefault="00651722"><w:r><w:t xml:space="preserve">This is a template for the </w:t></w:r><w:r><w:t>xyz</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t></w:r><w:r w:rsidR="00507D2F"><w:t>, page 1</w:t></w:r></w:p><w:p w:rsidR="00507D2F" w:rsidRDefault="00507D2F"><w:r><w:br w:type="page" /></w:r></w:p><w:p w:rsidP="007B2B98" w:rsidR="00EC3BBB" w:rsidRDefault="00507D2F" w:rsidRPr="00651722"><w:r><w:lastRenderedPageBreak /><w:t xml:space="preserve">This is a template for the </w:t></w:r><w:r><w:t>xyz</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t></w:r><w:r><w:t>, page 2</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:sectPr w:rsidR="00EC3BBB" w:rsidRPr="00651722"><w:headerReference ns1:id="rId7" w:type="default" /><w:footerReference ns1:id="rId8" w:type="default" /><w:pgSz w:h="15840" w:w="12240" /><w:pgMar w:bottom="1440" w:footer="708" w:gutter="0" w:header="708" w:left="1440" w:right="1440" w:top="1440" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body><w:br w:type="page" /><w:body><w:p w:rsidP="007B2B98" w:rsidR="00507D2F" w:rsidRDefault="00651722"><w:r><w:t xml:space="preserve">This is a template for the </w:t></w:r><w:r><w:t>abc</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t></w:r><w:r w:rsidR="00507D2F"><w:t>, page 1</w:t></w:r></w:p><w:p w:rsidR="00507D2F" w:rsidRDefault="00507D2F"><w:r><w:br w:type="page" /></w:r></w:p><w:p w:rsidP="007B2B98" w:rsidR="00EC3BBB" w:rsidRDefault="00507D2F" w:rsidRPr="00651722"><w:r><w:lastRenderedPageBreak /><w:t xml:space="preserve">This is a template for the </w:t></w:r><w:r><w:t>abc</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t></w:r><w:r><w:t>, page 2</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:sectPr w:rsidR="00EC3BBB" w:rsidRPr="00651722"><w:headerReference ns1:id="rId7" w:type="default" /><w:footerReference ns1:id="rId8" w:type="default" /><w:pgSz w:h="15840" w:w="12240" /><w:pgMar w:bottom="1440" w:footer="708" w:gutter="0" w:header="708" w:left="1440" w:right="1440" w:top="1440" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body><w:br w:type="page" /><w:body><w:p w:rsidP="007B2B98" w:rsidR="00507D2F" w:rsidRDefault="00651722"><w:r><w:t xml:space="preserve">This is a template for the </w:t></w:r><w:r><w:t>2b v ~2b</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t></w:r><w:r w:rsidR="00507D2F"><w:t>, page 1</w:t></w:r></w:p><w:p w:rsidR="00507D2F" w:rsidRDefault="00507D2F"><w:r><w:br w:type="page" /></w:r></w:p><w:p w:rsidP="007B2B98" w:rsidR="00EC3BBB" w:rsidRDefault="00507D2F" w:rsidRPr="00651722"><w:r><w:lastRenderedPageBreak /><w:t xml:space="preserve">This is a template for the </w:t></w:r><w:r><w:t>2b v ~2b</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t></w:r><w:r><w:t>, page 2</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:sectPr w:rsidR="00EC3BBB" w:rsidRPr="00651722"><w:headerReference ns1:id="rId7" w:type="default" /><w:footerReference ns1:id="rId8" w:type="default" /><w:pgSz w:h="15840" w:w="12240" /><w:pgMar w:bottom="1440" w:footer="708" w:gutter="0" w:header="708" w:left="1440" w:right="1440" w:top="1440" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body></w:document>'
        )  # noqa

        self.assert_equal_tree(expected_tree,
                               get_document_body_part(document).getroot())
Example #6
0
def generate():
    target = os.path.join(APP_ROOT, 'static/')

    for template in request.files.getlist("file"):
        print(template)
        filename = template.filename
    document = MailMerge(template)
    print(document.get_merge_fields())
    {'name', 'address', 'serial', 'number', 'issued'}
    cur = mysql.connection.cursor()
    if request.method == 'POST':
        id = request.form['id']
        cur.execute("SELECT * FROM users where id = %s", [id])
        result = cur.fetchall()
        for user in result:
            name = user[1]
            address = user[2]
            serial = user[3]
            number = user[4]
            issued = user[5]

        document.merge(name=user[1],
                       date='{:%d-%m-%Y}'.format(datetime.now()),
                       address=user[2],
                       serial=user[3],
                       number=user[4],
                       issued=user[5])
        document.write('static/test.docx')
    return render_template("complete.html")
Example #7
0
    def merge_test(self):
        template = "..\\data\\Template.docx"

        document = MailMerge(template)
        print(document.get_merge_fields())

        data = {
            'cdm_total': "232",
            'made_by': "최인수",
            'KOMPSAT-2': "123",
            'asdfasd': '12321'
        }

        row = {
            'last_cdm_creation': "test",
            'CDM_NO': "test",
            'CREATION_DATE': "test",
            'PROBABILITY': "test",
            'TCA': "test",
            'EVENTNUM': "test",
            'MISS_DISTANCE': "test",
            'SAT1_NAME': "test",
            'SAT1_NORAD': "test",
        }

        rows = [row, row]

        print(type(data))
        document.merge_rows('CDM_NO', rows)
        document.merge_templates([data], separator='page_break')

        document.write("..\\data\\result.docx")
    def test_pages(self):
        document = MailMerge(
            path.join(path.dirname(__file__), 'test_merge_pages.docx'))
        self.assertEqual(document.get_merge_fields(), {'fieldname'})

        document.merge_pages([
            {
                'fieldname': "xyz"
            },
            {
                'fieldname': "abc"
            },
            {
                'fieldname': "2b v ~2b"
            },
        ])

        with tempfile.TemporaryFile() as outfile:
            document.write(outfile)

        expected_tree = etree.fromstring(
            '<w:document xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ns1="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" mc:Ignorable="w14 wp14"><w:body><w:p w:rsidP="007B2B98" w:rsidR="00EC3BBB" w:rsidRDefault="00651722" w:rsidRPr="00651722"><w:r><w:t xml:space="preserve">This is a template for the </w:t></w:r><w:r><w:t>xyz</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:sectPr w:rsidR="00EC3BBB" w:rsidRPr="00651722"><w:headerReference ns1:id="rId7" w:type="default" /><w:footerReference ns1:id="rId8" w:type="default" /><w:pgSz w:h="15840" w:w="12240" /><w:pgMar w:bottom="1440" w:footer="708" w:gutter="0" w:header="708" w:left="1440" w:right="1440" w:top="1440" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body><w:br w:type="page" /><w:body><w:p w:rsidP="007B2B98" w:rsidR="00EC3BBB" w:rsidRDefault="00651722" w:rsidRPr="00651722"><w:r><w:t xml:space="preserve">This is a template for the </w:t></w:r><w:r><w:t>abc</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:sectPr w:rsidR="00EC3BBB" w:rsidRPr="00651722"><w:headerReference ns1:id="rId7" w:type="default" /><w:footerReference ns1:id="rId8" w:type="default" /><w:pgSz w:h="15840" w:w="12240" /><w:pgMar w:bottom="1440" w:footer="708" w:gutter="0" w:header="708" w:left="1440" w:right="1440" w:top="1440" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body><w:br w:type="page" /><w:body><w:p w:rsidP="007B2B98" w:rsidR="00EC3BBB" w:rsidRDefault="00651722" w:rsidRPr="00651722"><w:r><w:t xml:space="preserve">This is a template for the </w:t></w:r><w:r><w:t>2b v ~2b</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:sectPr w:rsidR="00EC3BBB" w:rsidRPr="00651722"><w:headerReference ns1:id="rId7" w:type="default" /><w:footerReference ns1:id="rId8" w:type="default" /><w:pgSz w:h="15840" w:w="12240" /><w:pgMar w:bottom="1440" w:footer="708" w:gutter="0" w:header="708" w:left="1440" w:right="1440" w:top="1440" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body></w:document>'
        )  # noqa

        self.assert_equal_tree(expected_tree,
                               get_document_body_part(document).getroot())
Example #9
0
    def mail_merge(self, company_name):

        #template1 = 'test1.docx'
        template2 = 'Executive_Summary2.docx'

        document = MailMerge(template2)
        print (document.get_merge_fields())
        #merge fields
        #{'ZIP_Code', 'Address_Line_2', 'Country_or_Region',
        #'Address_Line_1', 'Company_Name', 'Title',
        # 'State', 'City', 'First_Name', 'Work_Phone',
        #'Email_Address', 'Home_Phone', 'Last_Name'}

        document.merge(Title = 'Mr',
                        First_Name ='Joe',
                        Last_Name = 'OShea',
                        Company_Name = 'Principal Systems',
                        Email_Address= '*****@*****.**',
                        City = 'Dublin',
                        State = 'Dublin',
                        Work_Phone ='123333',
                        Address_Line_1 ='56 Pembrooke road',
                        Address_Line_2='Ballsbridge',
                        Home_Phone='1234567',
                        Country_or_Region='Ireland',
                        ZIP_Code = 'Dublin6')

        output = company_name + '_output.docx'
        document.write(output)
        return  output
Example #10
0
    def test(self):
        """
        Test the case when Word splits a MergeField w:instrText into several pieces
        (Note the test document is a valid word document generated by Word 2007)
        """
        document = MailMerge('tests/test_split_merge.docx')
        self.assertEquals(
            document.get_merge_fields(),
            set(['name_pinyin', 'name', 'semester', 'academic_year', 'date']))

        with tempfile.NamedTemporaryFile() as outfile:
            document.write(outfile)
    def test(self):
        """
        Test the case when Word splits a MergeField w:instrText into several pieces
        (Note the test document is a valid word document generated by Word 2007)
        """
        document = MailMerge('tests/test_split_merge.docx')
        self.assertEquals(document.get_merge_fields(),
                          set(['name_pinyin', 'name', 'semester',
                               'academic_year', 'date']))

        with tempfile.NamedTemporaryFile() as outfile:
            document.write(outfile)
    def test(self):
        document = MailMerge(
            path.join(path.dirname(__file__), 'test_winword2010.docx'))
        self.assertEqual(
            document.get_merge_fields(),
            set([
                'Titel', 'Voornaam', 'Achternaam', 'Adresregel_1', 'Postcode',
                'Plaats', 'Provincie', 'Land_of_regio'
            ]))

        document.merge(Voornaam='Bouke',
                       Achternaam='Haarsma',
                       Land_of_regio='The Netherlands',
                       Provincie=None,
                       Postcode='9723 ZA',
                       Plaats='Groningen',
                       Adresregel_1='Helperpark 278d',
                       Titel='dhr.')

        with tempfile.NamedTemporaryFile() as outfile:
            document.write(outfile)

        expected_tree = ElementTree.fromstring(
            '<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p '
            'w:rsidR="00886208" w:rsidRDefault="00886208"><w:r><w:t>dhr.</w:t></w:r><w:r '
            'w:rsidRPr="00886208"><w:rPr><w:lang w:val="nl-NL" /></w:rPr><w:t xml:space="preserve"> '
            '</w:t></w:r><w:r><w:t>Bouke</w:t></w:r><w:r w:rsidRPr="00886208"><w:rPr><w:lang w:val="nl-NL" '
            '/></w:rPr><w:t xml:space="preserve"> </w:t></w:r><w:r><w:t>Haarsma</w:t></w:r></w:p><w:p '
            'w:rsidR="00886208" w:rsidRDefault="00886208" w:rsidRPr="00886208"><w:pPr><w:rPr><w:lang w:val="nl-NL" '
            '/></w:rPr></w:pPr><w:r><w:t>Helperpark 278d</w:t></w:r></w:p><w:p w:rsidR="00886208" '
            'w:rsidRDefault="00886208"><w:r><w:t>9723 ZA</w:t></w:r><w:r w:rsidRPr="00886208"><w:rPr><w:lang '
            'w:val="nl-NL" /></w:rPr><w:t xml:space="preserve"> </w:t></w:r><w:r><w:t>Groningen</w:t></w:r><w:r '
            'w:rsidRPr="00886208"><w:rPr><w:lang w:val="nl-NL" /></w:rPr><w:t xml:space="preserve"> '
            '</w:t></w:r><w:r><w:t /></w:r><w:r w:rsidRPr="00886208"><w:rPr><w:lang w:val="nl-NL" /></w:rPr><w:t '
            'xml:space="preserve"> </w:t></w:r><w:r><w:t>The Netherlands</w:t></w:r></w:p><w:p w:rsidR="00886208" '
            'w:rsidRDefault="00886208" /><w:p w:rsidR="00886208" w:rsidRDefault="00886208"><w:r><w:t>Groningen,'
            '</w:t></w:r></w:p><w:p w:rsidR="00886208" w:rsidRDefault="00886208"><w:bookmarkStart w:id="0" '
            'w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:p w:rsidR="004D7161" '
            'w:rsidRDefault="00886208"><w:r><w:t xml:space="preserve">Dear '
            '</w:t></w:r><w:r><w:t>Bouke</w:t></w:r><w:r><w:t>,</w:t></w:r></w:p><w:p w:rsidR="00886208" '
            'w:rsidRDefault="00886208" /><w:p w:rsidR="00886208" w:rsidRDefault="00886208"><w:r><w:t>I hope this '
            'document from WinWord 2010 finds you well.</w:t></w:r></w:p><w:p w:rsidR="00886208" '
            'w:rsidRDefault="00886208" /><w:p w:rsidR="00886208" w:rsidRDefault="00886208"><w:r><w:t>Kind regards,'
            '</w:t></w:r></w:p><w:p w:rsidR="00886208" w:rsidRDefault="00886208" '
            'w:rsidRPr="00886208"><w:pPr><w:rPr><w:lang w:val="en-US" /></w:rPr></w:pPr><w:proofErr '
            'w:type="spellStart" /><w:r><w:t>docx-mailmerge</w:t></w:r><w:proofErr w:type="spellEnd" /><w:r><w:t>'
            '.</w:t></w:r></w:p><w:sectPr w:rsidR="00886208" w:rsidRPr="00886208"><w:pgSz w:h="16838" w:w="11906" '
            '/><w:pgMar w:bottom="1417" w:footer="708" w:gutter="0" w:header="708" w:left="1417" w:right="1417" '
            'w:top="1417" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body></w:document>'
        )

        self.assert_equal_tree(expected_tree,
                               list(document.parts.values())[0].getroot())
    def test_paged(self):
        document = MailMerge(path.join(path.dirname(__file__), 'test_merge_list_paged.docx'))
        self.assertEqual(document.get_merge_fields(), {'fieldname'})

        document.merge_list([
            {'fieldname': "xyz"},
            {'fieldname': "abc"},
            {'fieldname': "2b v ~2b"},
       ])

        with tempfile.TemporaryFile() as outfile:
            document.write(outfile)

        expected_tree = ElementTree.fromstring(
            '<w:document xmlns:ns1="http://schemas.openxmlformats.org/officeDocument/2006/relationships"'
            ' xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p w:rsidP="007B2B98"'
            ' w:rsidR="00507D2F" w:rsidRDefault="00651722"><w:r><w:t xml:space="preserve">This is a template for'
            ' the </w:t></w:r><w:r><w:t>xyz</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t>'
            '</w:r><w:r w:rsidR="00507D2F"><w:t>, page 1</w:t></w:r></w:p><w:p w:rsidR="00507D2F" w:rsidRDefault="00507D2F">'
            '<w:r><w:br w:type="page" /></w:r></w:p><w:p w:rsidP="007B2B98" w:rsidR="00EC3BBB" w:rsidRDefault="00507D2F"'
            ' w:rsidRPr="00651722"><w:r><w:lastRenderedPageBreak /><w:t xml:space="preserve">This is a template for the'
            ' </w:t></w:r><w:r><w:t>xyz</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t></w:r><w:r>'
            '<w:t>, page 2</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p>'
            '<w:sectPr w:rsidR="00EC3BBB" w:rsidRPr="00651722"><w:headerReference ns1:id="rId7" w:type="default" />'
            '<w:footerReference ns1:id="rId8" w:type="default" /><w:pgSz w:h="15840" w:w="12240" /><w:pgMar'
            ' w:bottom="1440" w:footer="708" w:gutter="0" w:header="708" w:left="1440" w:right="1440" w:top="1440"'
            ' /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body><w:br w:type="page" />'
            '<w:body><w:p w:rsidP="007B2B98" w:rsidR="00507D2F" w:rsidRDefault="00651722"><w:r><w:t xml:space="preserve"'
            '>This is a template for the </w:t></w:r><w:r><w:t>abc</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list'
            ' test case</w:t></w:r><w:r w:rsidR="00507D2F"><w:t>, page 1</w:t></w:r></w:p><w:p w:rsidR="00507D2F"'
            ' w:rsidRDefault="00507D2F"><w:r><w:br w:type="page" /></w:r></w:p><w:p w:rsidP="007B2B98" w:rsidR="00EC3BBB"'
            ' w:rsidRDefault="00507D2F" w:rsidRPr="00651722"><w:r><w:lastRenderedPageBreak /><w:t xml:space="preserve">'
            'This is a template for the </w:t></w:r><w:r><w:t>abc</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list'
            ' test case</w:t></w:r><w:r><w:t>, page 2</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack" />'
            '<w:bookmarkEnd w:id="0" /></w:p><w:sectPr w:rsidR="00EC3BBB" w:rsidRPr="00651722"><w:headerReference'
            ' ns1:id="rId7" w:type="default" /><w:footerReference ns1:id="rId8" w:type="default" /><w:pgSz w:h="15840"'
            ' w:w="12240" /><w:pgMar w:bottom="1440" w:footer="708" w:gutter="0" w:header="708" w:left="1440"'
            ' w:right="1440" w:top="1440" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body>'
            '<w:br w:type="page" /><w:body><w:p w:rsidP="007B2B98" w:rsidR="00507D2F" w:rsidRDefault="00651722"><w:r>'
            '<w:t xml:space="preserve">This is a template for the </w:t></w:r><w:r><w:t>2b v ~2b</w:t></w:r><w:r><w:t'
            ' xml:space="preserve"> merge_list test case</w:t></w:r><w:r w:rsidR="00507D2F"><w:t>, page 1</w:t></w:r>'
            '</w:p><w:p w:rsidR="00507D2F" w:rsidRDefault="00507D2F"><w:r><w:br w:type="page" /></w:r></w:p><w:p'
            ' w:rsidP="007B2B98" w:rsidR="00EC3BBB" w:rsidRDefault="00507D2F" w:rsidRPr="00651722"><w:r>'
            '<w:lastRenderedPageBreak /><w:t xml:space="preserve">This is a template for the </w:t></w:r><w:r><w:t>2b'
            ' v ~2b</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t></w:r><w:r><w:t>, page 2</w:t>'
            '</w:r><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:sectPr w:rsidR="00EC3BBB"'
            ' w:rsidRPr="00651722"><w:headerReference ns1:id="rId7" w:type="default" /><w:footerReference ns1:id="rId8"'
            ' w:type="default" /><w:pgSz w:h="15840" w:w="12240" /><w:pgMar w:bottom="1440" w:footer="708" w:gutter="0"'
            ' w:header="708" w:left="1440" w:right="1440" w:top="1440" /><w:cols w:space="708" /><w:docGrid'
            ' w:linePitch="360" /></w:sectPr></w:body></w:document>')

        self.assert_equal_tree(expected_tree, get_document_body_part(document).getroot())
class MergeTableRowsMultipartTest(EtreeMixin, unittest.TestCase):
    def setUp(self):
        self.document = MailMerge(path.join(path.dirname(__file__), 'test_merge_table_multipart.docx'))
        self.expected_xml = '<w:document xmlns:ns1="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p w:rsidP="00DA4DE0" w:rsidR="00231DA5" w:rsidRDefault="00DA4DE0"><w:pPr><w:pStyle w:val="Ttulo" /></w:pPr><w:r><w:t>Grades</w:t></w:r></w:p><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:r><w:t>Bouke Haarsma</w:t></w:r><w:r w:rsidR="002C29C5"><w:t xml:space="preserve"> </w:t></w:r><w:r w:rsidR="00DA4DE0"><w:t>received the grades</w:t></w:r><w:r w:rsidR="002C29C5"><w:t xml:space="preserve"> for </w:t></w:r><w:r><w:t /></w:r><w:r w:rsidR="00DA4DE0"><w:t xml:space="preserve"> in the table below.</w:t></w:r></w:p><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0" /><w:tbl><w:tblPr><w:tblStyle w:val="Sombreadoclaro-nfasis1" /><w:tblW w:type="auto" w:w="0" /><w:tblLook w:val="04E0" /></w:tblPr><w:tblGrid><w:gridCol w:w="1777" /><w:gridCol w:w="4894" /><w:gridCol w:w="1845" /></w:tblGrid><w:tr w:rsidR="00DA4DE0" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:val="100000000000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0"><w:r><w:t>Class Code</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0"><w:pPr><w:cnfStyle w:val="100000000000" /></w:pPr><w:r><w:t>Class Name</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0"><w:pPr><w:cnfStyle w:val="100000000000" /></w:pPr><w:r><w:t>Grade</w:t></w:r></w:p></w:tc></w:tr><w:tr w:rsidR="00DA4DE0" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:val="000000100000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:r><w:t>ECON101</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:pPr><w:cnfStyle w:val="000000100000" /></w:pPr><w:r><w:t>Economics 101</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:pPr><w:cnfStyle w:val="000000100000" /></w:pPr><w:r><w:t>A</w:t></w:r></w:p></w:tc></w:tr><w:tr w:rsidR="00DA4DE0" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:val="000000100000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:r><w:t>ECONADV</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:pPr><w:cnfStyle w:val="000000100000" /></w:pPr><w:r><w:t>Economics Advanced</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:pPr><w:cnfStyle w:val="000000100000" /></w:pPr><w:r><w:t>B</w:t></w:r></w:p></w:tc></w:tr><w:tr w:rsidR="00DA4DE0" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:val="000000100000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:r><w:t>OPRES</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:pPr><w:cnfStyle w:val="000000100000" /></w:pPr><w:r><w:t>Operations Research</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:pPr><w:cnfStyle w:val="000000100000" /></w:pPr><w:r><w:t>A</w:t></w:r></w:p></w:tc></w:tr><w:tr w:rsidR="00C829DD" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:val="010000000000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00C829DD" w:rsidRDefault="00C829DD"><w:r><w:t>THESIS</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00C829DD" w:rsidRDefault="00C829DD"><w:pPr><w:cnfStyle w:val="010000000000" /></w:pPr><w:r><w:t>Final thesis</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00C829DD" w:rsidRDefault="0037127B"><w:pPr><w:cnfStyle w:val="010000000000" /></w:pPr><w:r><w:t>A</w:t></w:r></w:p></w:tc></w:tr></w:tbl><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0" w:rsidRPr="00DA4DE0"><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:sectPr w:rsidR="00DA4DE0" w:rsidRPr="00DA4DE0" w:rsidSect="003B4151"><w:headerReference ns1:id="rId7" w:type="default" /><w:pgSz w:h="16840" w:w="11900" /><w:pgMar w:bottom="1440" w:footer="708" w:gutter="0" w:header="708" w:left="1800" w:right="1800" w:top="1672" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body></w:document>'
        self.expected_tree = etree.fromstring(self.expected_xml) 

    def test_merge_rows_on_multipart_file(self):
        self.assertEqual(self.document.get_merge_fields(),
                         {'student_name', 'study_name', 'class_name', 'class_code', 'class_grade', 'thesis_grade'})

        self.document.merge(
            student_name='Bouke Haarsma',
            study='Industrial Engineering and Management',
            thesis_grade='A',
        )

        self.document.merge_rows('class_code', [
            {'class_code': 'ECON101', 'class_name': 'Economics 101', 'class_grade': 'A'},
            {'class_code': 'ECONADV', 'class_name': 'Economics Advanced', 'class_grade': 'B'},
            {'class_code': 'OPRES', 'class_name': 'Operations Research', 'class_grade': 'A'},
        ])

        with tempfile.TemporaryFile() as outfile:
            self.document.write(outfile)

        for part in self.document.parts.values():
            # only check the document part 
            if (part.getroot().tag == '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}document'):
                self.assert_equal_tree(self.expected_tree, part.getroot())

    def test_merge_unified_on_multipart_file(self):
        self.document.merge(
            student_name='Bouke Haarsma',
            study='Industrial Engineering and Management',
            thesis_grade='A',
            class_code=[
                {'class_code': 'ECON101', 'class_name': 'Economics 101', 'class_grade': 'A'},
                {'class_code': 'ECONADV', 'class_name': 'Economics Advanced', 'class_grade': 'B'},
                {'class_code': 'OPRES', 'class_name': 'Operations Research', 'class_grade': 'A'},
            ]
        )

        with tempfile.TemporaryFile() as outfile:
            self.document.write(outfile)

        for part in self.document.parts.values():
            # only check the document part 
            if (part.getroot().tag == '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}document'):
                self.assert_equal_tree(self.expected_tree, part.getroot())

    def tearDown(self):
        self.document.close()
    def test(self):
        document = MailMerge('tests/test_macword2011.docx')
        self.assertEquals(document.get_merge_fields(),
                          set(['first_name', 'last_name', 'country', 'state',
                               'postal_code', 'date', 'address_line', 'city']))

        document.merge(first_name='Bouke', last_name='Haarsma',
                       country='The Netherlands', state=None,
                       postal_code='9723 ZA', city='Groningen',
                       address_line='Helperpark 278d', date='May 22nd, 2013')

        with tempfile.NamedTemporaryFile() as outfile:
            document.write(outfile)
    def test(self):
        document = MailMerge('tests/test_winword2010.docx')
        self.assertEquals(document.get_merge_fields(),
                          set(['Titel', 'Voornaam', 'Achternaam',
                               'Adresregel_1', 'Postcode', 'Plaats',
                               'Provincie', 'Land_of_regio']))

        document.merge(Voornaam='Bouke', Achternaam='Haarsma',
                       Land_of_regio='The Netherlands', Provincie=None,
                       Postcode='9723 ZA', Plaats='Groningen',
                       Adresregel_1='Helperpark 278d', Titel='dhr.')

        with tempfile.NamedTemporaryFile() as outfile:
            document.write(outfile.name)
    def test(self):
        document = MailMerge(path.join(path.dirname(__file__), 'test_macword2011.docx'))
        self.assertEqual(document.get_merge_fields(),
                         set(['first_name', 'last_name', 'country', 'state',
                              'postal_code', 'date', 'address_line', 'city']))

        document.merge(first_name='Bouke', last_name='Haarsma',
                       country='The Netherlands', state=None,
                       postal_code='9723 ZA', city='Groningen',
                       address_line='Helperpark 278d', date='May 22nd, 2013')

        with tempfile.TemporaryFile() as outfile:
            document.write(outfile)

        expected_tree = etree.fromstring(
            '<w:document xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" '
            'xmlns:ns1="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w="http://schemas'
            '.openxmlformats.org/wordprocessingml/2006/main" mc:Ignorable="w14 wp14">'
            '<w:body><w:p ns1:paraId="25CDEC86" ns1:textId="77777777" '
            'w:rsidR="00FB567A" w:rsidRDefault="00541684"><w:r><w:t>Bouke</w:t></w:r><w:r w:rsidR="00916690"><w:t '
            'xml:space="preserve"> </w:t></w:r><w:r><w:t>Haarsma</w:t></w:r></w:p><w:p ns1:paraId="67F7A559" '
            'ns1:textId="77777777" w:rsidR="00916690" w:rsidRDefault="00541684"><w:r><w:t>Helperpark '
            '278d</w:t></w:r></w:p><w:p ns1:paraId="228F2AEA" ns1:textId="77777777" w:rsidR="00916690" '
            'w:rsidRDefault="00541684"><w:r><w:t>9723 ZA</w:t></w:r><w:r><w:t xml:space="preserve"> '
            '</w:t></w:r><w:r><w:t>Groningen</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd '
            'w:id="0" /><w:r w:rsidR="00916690"><w:t xml:space="preserve"> </w:t></w:r><w:r><w:t /></w:r><w:r '
            'w:rsidR="00916690"><w:t xml:space="preserve"> </w:t></w:r><w:r><w:t>The '
            'Netherlands</w:t></w:r></w:p><w:p ns1:paraId="696E15D7" ns1:textId="77777777" w:rsidR="00916690" '
            'w:rsidRDefault="00916690" /><w:p ns1:paraId="3F48DA35" ns1:textId="77777777" w:rsidR="00916690" '
            'w:rsidRDefault="00916690" /><w:p ns1:paraId="68E7FBD1" ns1:textId="77777777" w:rsidR="00916690" '
            'w:rsidRDefault="00916690"><w:r><w:t xml:space="preserve">Groningen, </w:t></w:r><w:r><w:t>May 22nd, '
            '2013</w:t></w:r><w:r><w:t>,</w:t></w:r></w:p><w:p ns1:paraId="26B47597" ns1:textId="77777777" '
            'w:rsidR="00916690" w:rsidRDefault="00916690" /><w:p ns1:paraId="740FF493" ns1:textId="77777777" '
            'w:rsidR="00916690" w:rsidRDefault="00916690" /><w:p ns1:paraId="232699A0" ns1:textId="77777777" '
            'w:rsidR="00916690" w:rsidRDefault="00916690"><w:r><w:t xml:space="preserve">Dear '
            '</w:t></w:r><w:r><w:t>Bouke</w:t></w:r><w:r><w:t>,</w:t></w:r></w:p><w:p ns1:paraId="1AE04A19" '
            'ns1:textId="77777777" w:rsidR="00916690" w:rsidRDefault="00916690" /><w:p ns1:paraId="298752B0" '
            'ns1:textId="77777777" w:rsidR="00916690" w:rsidRDefault="00916690" /><w:p ns1:paraId="477BE6DB" '
            'ns1:textId="77777777" w:rsidR="00916690" w:rsidRDefault="00916690"><w:r><w:t>I hope this message finds '
            'you well.</w:t></w:r></w:p><w:p ns1:paraId="77542CE2" ns1:textId="77777777" w:rsidR="00916690" '
            'w:rsidRDefault="00916690" /><w:p ns1:paraId="734AC552" ns1:textId="77777777" w:rsidR="00916690" '
            'w:rsidRDefault="00916690" /><w:p ns1:paraId="1680D84C" ns1:textId="77777777" w:rsidR="00916690" '
            'w:rsidRDefault="00916690"><w:r><w:t>Kind regards,</w:t></w:r></w:p><w:p ns1:paraId="67F698AC" '
            'ns1:textId="77777777" w:rsidR="00916690" w:rsidRDefault="00916690" /><w:p ns1:paraId="7A4C001B" '
            'ns1:textId="77777777" w:rsidR="00916690" w:rsidRDefault="00916690"><w:r><w:t>docx-mailmerge'
            '.</w:t></w:r></w:p><w:sectPr w:rsidR="00916690" w:rsidSect="00CA5A66"><w:pgSz w:h="16840" w:w="11900" '
            '/><w:pgMar w:bottom="1417" w:footer="708" w:gutter="0" w:header="708" w:left="1417" w:right="1417" '
            'w:top="1417" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body></w:document>')

        self.assert_equal_tree(expected_tree, list(document.parts.values())[0].getroot())
class MergeTableRowsMultipartTest(EtreeMixin, unittest.TestCase):
    def setUp(self):
        self.document = MailMerge(path.join(path.dirname(__file__), 'test_merge_table_multipart.docx'))
        self.expected_xml = '<w:document xmlns:ns1="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p w:rsidP="00DA4DE0" w:rsidR="00231DA5" w:rsidRDefault="00DA4DE0"><w:pPr><w:pStyle w:val="Ttulo" /></w:pPr><w:r><w:t>Grades</w:t></w:r></w:p><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:r><w:t>Bouke Haarsma</w:t></w:r><w:r w:rsidR="002C29C5"><w:t xml:space="preserve"> </w:t></w:r><w:r w:rsidR="00DA4DE0"><w:t>received the grades</w:t></w:r><w:r w:rsidR="002C29C5"><w:t xml:space="preserve"> for </w:t></w:r><w:r><w:t /></w:r><w:r w:rsidR="00DA4DE0"><w:t xml:space="preserve"> in the table below.</w:t></w:r></w:p><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0" /><w:tbl><w:tblPr><w:tblStyle w:val="Sombreadoclaro-nfasis1" /><w:tblW w:type="auto" w:w="0" /><w:tblLook w:val="04E0" /></w:tblPr><w:tblGrid><w:gridCol w:w="1777" /><w:gridCol w:w="4894" /><w:gridCol w:w="1845" /></w:tblGrid><w:tr w:rsidR="00DA4DE0" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:val="100000000000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0"><w:r><w:t>Class Code</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0"><w:pPr><w:cnfStyle w:val="100000000000" /></w:pPr><w:r><w:t>Class Name</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0"><w:pPr><w:cnfStyle w:val="100000000000" /></w:pPr><w:r><w:t>Grade</w:t></w:r></w:p></w:tc></w:tr><w:tr w:rsidR="00DA4DE0" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:val="000000100000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:r><w:t>ECON101</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:pPr><w:cnfStyle w:val="000000100000" /></w:pPr><w:r><w:t>Economics 101</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:pPr><w:cnfStyle w:val="000000100000" /></w:pPr><w:r><w:t>A</w:t></w:r></w:p></w:tc></w:tr><w:tr w:rsidR="00DA4DE0" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:val="000000100000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:r><w:t>ECONADV</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:pPr><w:cnfStyle w:val="000000100000" /></w:pPr><w:r><w:t>Economics Advanced</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:pPr><w:cnfStyle w:val="000000100000" /></w:pPr><w:r><w:t>B</w:t></w:r></w:p></w:tc></w:tr><w:tr w:rsidR="00DA4DE0" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:val="000000100000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:r><w:t>OPRES</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:pPr><w:cnfStyle w:val="000000100000" /></w:pPr><w:r><w:t>Operations Research</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="0037127B"><w:pPr><w:cnfStyle w:val="000000100000" /></w:pPr><w:r><w:t>A</w:t></w:r></w:p></w:tc></w:tr><w:tr w:rsidR="00C829DD" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:val="010000000000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00C829DD" w:rsidRDefault="00C829DD"><w:r><w:t>THESIS</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00C829DD" w:rsidRDefault="00C829DD"><w:pPr><w:cnfStyle w:val="010000000000" /></w:pPr><w:r><w:t>Final thesis</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p w:rsidP="00DA4DE0" w:rsidR="00C829DD" w:rsidRDefault="0037127B"><w:pPr><w:cnfStyle w:val="010000000000" /></w:pPr><w:r><w:t>A</w:t></w:r></w:p></w:tc></w:tr></w:tbl><w:p w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0" w:rsidRPr="00DA4DE0"><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:sectPr w:rsidR="00DA4DE0" w:rsidRPr="00DA4DE0" w:rsidSect="003B4151"><w:headerReference ns1:id="rId7" w:type="default" /><w:pgSz w:h="16840" w:w="11900" /><w:pgMar w:bottom="1440" w:footer="708" w:gutter="0" w:header="708" w:left="1800" w:right="1800" w:top="1672" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body></w:document>'
        self.expected_tree = ElementTree.fromstring(self.expected_xml) 

    def test_merge_rows_on_multipart_file(self):
        self.assertEqual(self.document.get_merge_fields(),
                         {'student_name', 'study_name', 'class_name', 'class_code', 'class_grade', 'thesis_grade'})

        self.document.merge(
            student_name='Bouke Haarsma',
            study='Industrial Engineering and Management',
            thesis_grade='A',
        )

        self.document.merge_rows('class_code', [
            {'class_code': 'ECON101', 'class_name': 'Economics 101', 'class_grade': 'A'},
            {'class_code': 'ECONADV', 'class_name': 'Economics Advanced', 'class_grade': 'B'},
            {'class_code': 'OPRES', 'class_name': 'Operations Research', 'class_grade': 'A'},
        ])

        with tempfile.TemporaryFile() as outfile:
            self.document.write(outfile)

        for part in self.document.parts.values():
            # only check the document part 
            if (part.getroot().tag == '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}document'):
                self.assert_equal_tree(self.expected_tree, part.getroot())

    def test_merge_unified_on_multipart_file(self):
        self.document.merge(
            student_name='Bouke Haarsma',
            study='Industrial Engineering and Management',
            thesis_grade='A',
            class_code=[
                {'class_code': 'ECON101', 'class_name': 'Economics 101', 'class_grade': 'A'},
                {'class_code': 'ECONADV', 'class_name': 'Economics Advanced', 'class_grade': 'B'},
                {'class_code': 'OPRES', 'class_name': 'Operations Research', 'class_grade': 'A'},
            ]
        )

        with tempfile.TemporaryFile() as outfile:
            self.document.write(outfile)

        for part in self.document.parts.values():
            # only check the document part 
            if (part.getroot().tag == '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}document'):
                self.assert_equal_tree(self.expected_tree, part.getroot())
Example #19
0
def search_entry_and_generate_doc(name):
    print(name)
    document = MailMerge(template)
    print(document.get_merge_fields())
    with open('data.json') as infile:
        try:
            data = json.load(infile)
            print(data[name])
            output = data[name]
            document.merge(**output)
            document.write("output.docx")
            os.startfile("output.docx", "print")
        except Exception as e:
            print(e)
            messagebox.showerror("Error", "File doesnot have any record")
Example #20
0
def generateDoc(request):
    template = "templates/will_templates/will_template.docx"

    document = MailMerge(template)
    print("printing things")
    print(document.get_merge_fields())
    document.merge({
        'full_name': 'Abc Something',
        'address': "1300, Yates Street",
        'spouse_name': "Def Something",
        'spouse_address': "1301 Yates Street"
    })
    document.write('test-output.docx')

    return HttpResponse("Aparently the doc is created!")
    def test_pages(self):
        document = MailMerge(path.join(path.dirname(__file__), 'test_merge_pages.docx'))
        self.assertEqual(document.get_merge_fields(), {'fieldname'})

        document.merge_pages([
            {'fieldname': "xyz"},
            {'fieldname': "abc"},
            {'fieldname': "2b v ~2b"},
        ])

        with tempfile.TemporaryFile() as outfile:
            document.write(outfile)

        expected_tree = etree.fromstring('<w:document xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ns1="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" mc:Ignorable="w14 wp14"><w:body><w:p w:rsidP="007B2B98" w:rsidR="00EC3BBB" w:rsidRDefault="00651722" w:rsidRPr="00651722"><w:r><w:t xml:space="preserve">This is a template for the </w:t></w:r><w:r><w:t>xyz</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:sectPr w:rsidR="00EC3BBB" w:rsidRPr="00651722"><w:headerReference ns1:id="rId7" w:type="default" /><w:footerReference ns1:id="rId8" w:type="default" /><w:pgSz w:h="15840" w:w="12240" /><w:pgMar w:bottom="1440" w:footer="708" w:gutter="0" w:header="708" w:left="1440" w:right="1440" w:top="1440" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body><w:br w:type="page" /><w:body><w:p w:rsidP="007B2B98" w:rsidR="00EC3BBB" w:rsidRDefault="00651722" w:rsidRPr="00651722"><w:r><w:t xml:space="preserve">This is a template for the </w:t></w:r><w:r><w:t>abc</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:sectPr w:rsidR="00EC3BBB" w:rsidRPr="00651722"><w:headerReference ns1:id="rId7" w:type="default" /><w:footerReference ns1:id="rId8" w:type="default" /><w:pgSz w:h="15840" w:w="12240" /><w:pgMar w:bottom="1440" w:footer="708" w:gutter="0" w:header="708" w:left="1440" w:right="1440" w:top="1440" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body><w:br w:type="page" /><w:body><w:p w:rsidP="007B2B98" w:rsidR="00EC3BBB" w:rsidRDefault="00651722" w:rsidRPr="00651722"><w:r><w:t xml:space="preserve">This is a template for the </w:t></w:r><w:r><w:t>2b v ~2b</w:t></w:r><w:r><w:t xml:space="preserve"> merge_list test case</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:sectPr w:rsidR="00EC3BBB" w:rsidRPr="00651722"><w:headerReference ns1:id="rId7" w:type="default" /><w:footerReference ns1:id="rId8" w:type="default" /><w:pgSz w:h="15840" w:w="12240" /><w:pgMar w:bottom="1440" w:footer="708" w:gutter="0" w:header="708" w:left="1440" w:right="1440" w:top="1440" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body></w:document>')  # noqa

        self.assert_equal_tree(expected_tree, get_document_body_part(document).getroot())
Example #22
0
 def mail(self):
     template = "a.docx"
     document = MailMerge(template)
     file = QFileDialog.getSaveFileName(self, 'Enregistrer Fichier',
                                        str(self.m.text()),
                                        ("Word file (*.docx)"))
     w = document.get_merge_fields()
     w = sorted(w)
     d = {}
     h = [0, 1, 2, 3, 4, 5]
     li = []
     for x in range(self.tbl.rowCount()):
         for i in range(len(h)):
             d[w[i]] = self.tbl.item(x, h[i]).text()
         li.append(dict(d))
     document.merge_pages(li)
     document.write(file[0])
Example #23
0
def instantiate_mailmerge(template_file):
    """Instantiate the MailMerge class

    :param template_file: {str} the template file
    :return document: {Object} the MailMerge instance 
    """
    document = MailMerge(template_file)

    logging.info(document.get_merge_fields())

    document.merge(
        document_prepared_by=g_document_prepared_by,
        document_prepared_date=g_document_prepared_date,
        software_name=g_software_name,
        software_version=g_software_version,
        server=g_server)

    return document
    def test(self):
        document = MailMerge(path.join(path.dirname(__file__), 'test_winword2010.docx'))
        self.assertEqual(document.get_merge_fields(),
                         set(['Titel', 'Voornaam', 'Achternaam',
                              'Adresregel_1', 'Postcode', 'Plaats',
                              'Provincie', 'Land_of_regio']))

        document.merge(Voornaam='Bouke', Achternaam='Haarsma',
                       Land_of_regio='The Netherlands', Provincie=None,
                       Postcode='9723 ZA', Plaats='Groningen',
                       Adresregel_1='Helperpark 278d', Titel='dhr.')

        with tempfile.NamedTemporaryFile() as outfile:
            document.write(outfile)

        expected_tree = ElementTree.fromstring(
            '<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p '
            'w:rsidR="00886208" w:rsidRDefault="00886208"><w:r><w:t>dhr.</w:t></w:r><w:r '
            'w:rsidRPr="00886208"><w:rPr><w:lang w:val="nl-NL" /></w:rPr><w:t xml:space="preserve"> '
            '</w:t></w:r><w:r><w:t>Bouke</w:t></w:r><w:r w:rsidRPr="00886208"><w:rPr><w:lang w:val="nl-NL" '
            '/></w:rPr><w:t xml:space="preserve"> </w:t></w:r><w:r><w:t>Haarsma</w:t></w:r></w:p><w:p '
            'w:rsidR="00886208" w:rsidRDefault="00886208" w:rsidRPr="00886208"><w:pPr><w:rPr><w:lang w:val="nl-NL" '
            '/></w:rPr></w:pPr><w:r><w:t>Helperpark 278d</w:t></w:r></w:p><w:p w:rsidR="00886208" '
            'w:rsidRDefault="00886208"><w:r><w:t>9723 ZA</w:t></w:r><w:r w:rsidRPr="00886208"><w:rPr><w:lang '
            'w:val="nl-NL" /></w:rPr><w:t xml:space="preserve"> </w:t></w:r><w:r><w:t>Groningen</w:t></w:r><w:r '
            'w:rsidRPr="00886208"><w:rPr><w:lang w:val="nl-NL" /></w:rPr><w:t xml:space="preserve"> '
            '</w:t></w:r><w:r><w:t /></w:r><w:r w:rsidRPr="00886208"><w:rPr><w:lang w:val="nl-NL" /></w:rPr><w:t '
            'xml:space="preserve"> </w:t></w:r><w:r><w:t>The Netherlands</w:t></w:r></w:p><w:p w:rsidR="00886208" '
            'w:rsidRDefault="00886208" /><w:p w:rsidR="00886208" w:rsidRDefault="00886208"><w:r><w:t>Groningen,'
            '</w:t></w:r></w:p><w:p w:rsidR="00886208" w:rsidRDefault="00886208"><w:bookmarkStart w:id="0" '
            'w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:p w:rsidR="004D7161" '
            'w:rsidRDefault="00886208"><w:r><w:t xml:space="preserve">Dear '
            '</w:t></w:r><w:r><w:t>Bouke</w:t></w:r><w:r><w:t>,</w:t></w:r></w:p><w:p w:rsidR="00886208" '
            'w:rsidRDefault="00886208" /><w:p w:rsidR="00886208" w:rsidRDefault="00886208"><w:r><w:t>I hope this '
            'document from WinWord 2010 finds you well.</w:t></w:r></w:p><w:p w:rsidR="00886208" '
            'w:rsidRDefault="00886208" /><w:p w:rsidR="00886208" w:rsidRDefault="00886208"><w:r><w:t>Kind regards,'
            '</w:t></w:r></w:p><w:p w:rsidR="00886208" w:rsidRDefault="00886208" '
            'w:rsidRPr="00886208"><w:pPr><w:rPr><w:lang w:val="en-US" /></w:rPr></w:pPr><w:proofErr '
            'w:type="spellStart" /><w:r><w:t>docx-mailmerge</w:t></w:r><w:proofErr w:type="spellEnd" /><w:r><w:t>'
            '.</w:t></w:r></w:p><w:sectPr w:rsidR="00886208" w:rsidRPr="00886208"><w:pgSz w:h="16838" w:w="11906" '
            '/><w:pgMar w:bottom="1417" w:footer="708" w:gutter="0" w:header="708" w:left="1417" w:right="1417" '
            'w:top="1417" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body></w:document>')

        self.assert_equal_tree(expected_tree, list(document.parts.values())[0].getroot())
class MergeTableRowsTest(EtreeMixin, unittest.TestCase):
    def setUp(self):
        self.document = MailMerge(path.join(path.dirname(__file__), 'test_merge_table_rows.docx'))
        self.expected_tree = ElementTree.fromstring('<w:document xmlns:ns1="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p ns1:paraId="28ACC80D" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00231DA5" w:rsidRDefault="00DA4DE0"><w:pPr><w:pStyle w:val="Title" /></w:pPr><w:proofErr w:type="spellStart" /><w:r><w:t>Grades</w:t></w:r><w:proofErr w:type="spellEnd" /></w:p><w:p ns1:paraId="07836F52" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00C829DD"><w:r><w:t>Bouke Haarsma</w:t></w:r><w:r w:rsidR="002C29C5"><w:t xml:space="preserve"> </w:t></w:r><w:proofErr w:type="spellStart" /><w:r w:rsidR="00DA4DE0"><w:t>received</w:t></w:r><w:proofErr w:type="spellEnd" /><w:r w:rsidR="00DA4DE0"><w:t xml:space="preserve"> the </w:t></w:r><w:proofErr w:type="spellStart" /><w:r w:rsidR="00DA4DE0"><w:t>grades</w:t></w:r><w:proofErr w:type="spellEnd" /><w:r w:rsidR="002C29C5"><w:t xml:space="preserve"> </w:t></w:r><w:proofErr w:type="spellStart" /><w:r w:rsidR="002C29C5"><w:t>for</w:t></w:r><w:proofErr w:type="spellEnd" /><w:r w:rsidR="002C29C5"><w:t xml:space="preserve"> </w:t></w:r><w:r><w:t /></w:r><w:r w:rsidR="00DA4DE0"><w:t xml:space="preserve"> in the </w:t></w:r><w:proofErr w:type="spellStart" /><w:r w:rsidR="00DA4DE0"><w:t>table</w:t></w:r><w:proofErr w:type="spellEnd" /><w:r w:rsidR="00DA4DE0"><w:t xml:space="preserve"> below.</w:t></w:r></w:p><w:p ns1:paraId="58525309" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0" /><w:tbl><w:tblPr><w:tblStyle w:val="LightShading-Accent1" /><w:tblW w:type="auto" w:w="0" /><w:tblLook w:firstColumn="1" w:firstRow="1" w:lastColumn="0" w:lastRow="1" w:noHBand="0" w:noVBand="1" w:val="04E0" /></w:tblPr><w:tblGrid><w:gridCol w:w="1777" /><w:gridCol w:w="4894" /><w:gridCol w:w="1845" /></w:tblGrid><w:tr ns1:paraId="599252DD" ns1:textId="77777777" w:rsidR="00DA4DE0" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="1" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="100000000000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="1" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p ns1:paraId="69486D96" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0"><w:r><w:t>Class Code</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p ns1:paraId="1AA11439" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0"><w:pPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="1" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="100000000000" /></w:pPr><w:r><w:t>Class Name</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p ns1:paraId="3091846F" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0"><w:pPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="1" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="100000000000" /></w:pPr><w:r><w:t>Grade</w:t></w:r></w:p></w:tc></w:tr><w:tr ns1:paraId="1699D5B6" ns1:textId="77777777" w:rsidR="00DA4DE0" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="1" w:oddVBand="0" w:val="000000100000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="1" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p ns1:paraId="5D81DF7F" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00C829DD"><w:r><w:t>ECON101</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p ns1:paraId="5A67E49A" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00C829DD"><w:pPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="1" w:oddVBand="0" w:val="000000100000" /></w:pPr><w:r><w:t>Economics 101</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p ns1:paraId="5EB9BD23" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00C829DD"><w:pPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="1" w:oddVBand="0" w:val="000000100000" /></w:pPr><w:r><w:t>A</w:t></w:r></w:p></w:tc></w:tr><w:tr ns1:paraId="1699D5B6" ns1:textId="77777777" w:rsidR="00DA4DE0" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="1" w:oddVBand="0" w:val="000000100000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="1" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p ns1:paraId="5D81DF7F" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00C829DD"><w:r><w:t>ECONADV</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p ns1:paraId="5A67E49A" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00C829DD"><w:pPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="1" w:oddVBand="0" w:val="000000100000" /></w:pPr><w:r><w:t>Economics Advanced</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p ns1:paraId="5EB9BD23" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00C829DD"><w:pPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="1" w:oddVBand="0" w:val="000000100000" /></w:pPr><w:r><w:t>B</w:t></w:r></w:p></w:tc></w:tr><w:tr ns1:paraId="1699D5B6" ns1:textId="77777777" w:rsidR="00DA4DE0" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="1" w:oddVBand="0" w:val="000000100000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="1" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p ns1:paraId="5D81DF7F" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00C829DD"><w:r><w:t>OPRES</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p ns1:paraId="5A67E49A" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00C829DD"><w:pPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="1" w:oddVBand="0" w:val="000000100000" /></w:pPr><w:r><w:t>Operations Research</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p ns1:paraId="5EB9BD23" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00C829DD"><w:pPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="1" w:oddVBand="0" w:val="000000100000" /></w:pPr><w:r><w:t>A</w:t></w:r></w:p></w:tc></w:tr><w:tr ns1:paraId="0B5730FD" ns1:textId="77777777" w:rsidR="00C829DD" w:rsidTr="00C829DD"><w:trPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="1" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="010000000000" /></w:trPr><w:tc><w:tcPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="1" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="001000000000" /><w:tcW w:type="dxa" w:w="1809" /></w:tcPr><w:p ns1:paraId="6A211A5A" ns1:textId="4E90EB38" w:rsidP="00DA4DE0" w:rsidR="00C829DD" w:rsidRDefault="00C829DD"><w:r><w:t>THESIS</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="5529" /></w:tcPr><w:p ns1:paraId="12FCE443" ns1:textId="289CA6C6" w:rsidP="00DA4DE0" w:rsidR="00C829DD" w:rsidRDefault="00C829DD"><w:pPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="1" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="010000000000" /></w:pPr><w:proofErr w:type="spellStart" /><w:r><w:t>Final</w:t></w:r><w:proofErr w:type="spellEnd" /><w:r><w:t xml:space="preserve"> thesis</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="1178" /></w:tcPr><w:p ns1:paraId="0ACD9198" ns1:textId="413A3A4D" w:rsidP="00DA4DE0" w:rsidR="00C829DD" w:rsidRDefault="00C829DD"><w:pPr><w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="1" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="010000000000" /></w:pPr><w:r><w:t>A</w:t></w:r></w:p></w:tc></w:tr></w:tbl><w:p ns1:paraId="26A87379" ns1:textId="77777777" w:rsidP="00DA4DE0" w:rsidR="00DA4DE0" w:rsidRDefault="00DA4DE0" w:rsidRPr="00DA4DE0"><w:bookmarkStart w:id="0" w:name="_GoBack" /><w:bookmarkEnd w:id="0" /></w:p><w:sectPr w:rsidR="00DA4DE0" w:rsidRPr="00DA4DE0" w:rsidSect="002C0659"><w:pgSz w:h="16840" w:w="11900" /><w:pgMar w:bottom="1440" w:footer="708" w:gutter="0" w:header="708" w:left="1800" w:right="1800" w:top="1440" /><w:cols w:space="708" /><w:docGrid w:linePitch="360" /></w:sectPr></w:body></w:document>')  # noqa

    def test_merge_rows(self):
        self.assertEqual(self.document.get_merge_fields(),
                         {'student_name', 'study_name', 'class_name', 'class_code', 'class_grade', 'thesis_grade'})

        self.document.merge(
            student_name='Bouke Haarsma',
            study='Industrial Engineering and Management',
            thesis_grade='A',
        )

        self.document.merge_rows('class_code', [
            {'class_code': 'ECON101', 'class_name': 'Economics 101', 'class_grade': 'A'},
            {'class_code': 'ECONADV', 'class_name': 'Economics Advanced', 'class_grade': 'B'},
            {'class_code': 'OPRES', 'class_name': 'Operations Research', 'class_grade': 'A'},
        ])

        with tempfile.TemporaryFile() as outfile:
            self.document.write(outfile)

        self.assert_equal_tree(self.expected_tree,
                               list(self.document.parts.values())[0].getroot())

    def test_merge_unified(self):
        self.document.merge(
            student_name='Bouke Haarsma',
            study='Industrial Engineering and Management',
            thesis_grade='A',
            class_code=[
                {'class_code': 'ECON101', 'class_name': 'Economics 101', 'class_grade': 'A'},
                {'class_code': 'ECONADV', 'class_name': 'Economics Advanced', 'class_grade': 'B'},
                {'class_code': 'OPRES', 'class_name': 'Operations Research', 'class_grade': 'A'},
            ]
        )

        with tempfile.TemporaryFile() as outfile:
            self.document.write(outfile)

        self.assert_equal_tree(self.expected_tree,
                               list(self.document.parts.values())[0].getroot())
Example #26
0
    def test(self):
        document = MailMerge('tests/test_macword2011.docx')
        self.assertEquals(
            document.get_merge_fields(),
            set([
                'first_name', 'last_name', 'country', 'state', 'postal_code',
                'date', 'address_line', 'city'
            ]))

        document.merge(first_name='Bouke',
                       last_name='Haarsma',
                       country='The Netherlands',
                       state=None,
                       postal_code='9723 ZA',
                       city='Groningen',
                       address_line='Helperpark 278d',
                       date='May 22nd, 2013')

        with tempfile.NamedTemporaryFile() as outfile:
            document.write(outfile)
    def test(self):
        document = MailMerge('tests/test_winword2010.docx')
        self.assertEquals(
            document.get_merge_fields(),
            set([
                'Titel', 'Voornaam', 'Achternaam', 'Adresregel_1', 'Postcode',
                'Plaats', 'Provincie', 'Land_of_regio'
            ]))

        document.merge(Voornaam='Bouke',
                       Achternaam='Haarsma',
                       Land_of_regio='The Netherlands',
                       Provincie=None,
                       Postcode='9723 ZA',
                       Plaats='Groningen',
                       Adresregel_1='Helperpark 278d',
                       Titel='dhr.')

        with tempfile.NamedTemporaryFile() as outfile:
            document.write(outfile)
Example #28
0
def updateCV():

    template = "Cover_Letter_Template.docx"

    #read the csv of jobs
    jobs_df = pd.read_csv('jobList.csv')
    jobs_df = jobs_df[['company', 'job_title']]
    jobs_df = jobs_df.sort_values(['company', 'job_title'])

    jobID = 1
    for row in jobs_df.itertuples():
        print(row[1])
        print(row[2])
        print('================================')

        document = MailMerge(template)
        print(document.get_merge_fields())

        #create a folder for each job
        try:
            folder_name = row[1].replace("/", "") + ' - ' + row[2].replace(
                "/", "")
            os.mkdir(folder_name)
        except Exception as e:
            company_name = row[1].replace("/", "")
            job_title = row[2].replace("/", "")
            folder_name = company_name[0:10] + ' - ' + job_title[0:10]
            try:
                os.mkdir(folder_name)
            except Exception as e:
                os.mkdir(folder_name + ' - ' + str(jobID))

        document.merge(company=row[1], position=row[2])

        try:
            document.write(folder_name + '\Cover Letter.docx')
        except Exception as e:
            # append a number in case there are duplicate folder names
            document.write(folder_name + ' - ' + str(jobID) +
                           '\Cover Letter.docx')
        jobID += 1
 def CreateDoc(self, issues):
     document = MailMerge(self.DocxSource)
     print(document.get_merge_fields())
     #Заголовок
     document.merge(ProjectName=self.Project)
     document.merge(VersionName=self.Version)        
     # Список ошибок
     dict = self.getIssuesDict(issues)
     document.merge_rows('IssueSubject', dict)
     # Номер ревизии    
     document.merge(Revision=str(self.Revision))
     # Ошибок найдено (кол-во / вес)        
     document.merge(IssuesTotal=str(len(issues)))
     document.merge(WeightsTotal=str(sum(issue.Weight for issue in issues)))
     # Ошибок не исправлено (кол-во / вес)
     document.merge(IssuesOpen=str(len([issue for issue in issues if not issue.Result])))
     document.merge(WeightsOpen=str(sum(issue.Weight for issue in issues if not issue.Result)))
     # Контрольная сумма (MD5)
     document.merge(InstallerChecksum=str(self.InstallerChecksum))
     # Сохранение дока
     document.write(self.DocxDestination)
def fill_template(name, hiring, address1, address2, remuneration, gender, num, clause1, clause2, clause3):
    template = "ABB_iT_LETTERA INDETERMINATO_impiegato.docx"
    document = MailMerge(template)
    print(document.get_merge_fields())
    # {'Date', 'Address1', 'hiring', 'Klauzula3', 'Name', 'Address2', 'Klauzula1', 'remuneration', 'salutation', 'Klauzula2'}
    remuneration = int(remuneration)
    remuneration_word = num2words(remuneration, lang='it') + "/00"
    if gender == 'M':
        salutation = "Gentile Sig."
    else:
        salutation = "Gentile Sig.ra"
    if clause1:
        clause1 = "To jest Klauzula 1\n \n"
    else:
        clause1 = ""

    if clause2:
        clause2 = "To jest Klauzula 2\n \n"
    else:
        clause2 = ""
    if clause3:
        clause3 = f"To jest Klauzula 3 z numerkiem {num}\n \n"
    else:
        clause3 = ""

    document.merge(
        Date='{:%d.%m.%Y}'.format(date.today()),
        salutation=salutation,
        Address1=address1,
        Address2=address2,
        hiring=hiring,
        name=name,
        remuneration=str(remuneration),
        remuneration_word=remuneration_word,
        Klauzula1=clause1,
        Klauzula2=clause2,
        Klauzula3=clause3,

    )
    document.write(f'{name}.docx')
Example #31
0
class DoxManagement:
    def __init__(self):
        print(platform.system())
        self.path = os.path.abspath('.') + "\static\word"
        self.pdf = os.path.abspath('.') + "\static\pdf"
        self.template = "test_template.docx"
        self.document_1 = MailMerge(self.template)

    # 文档生成
    def born_word(self, student_name, student_type, room_number, question_1,
                  question_2, question_3, question_4, question_5,
                  student_number):
        print("Fields included in {}: {}".format(
            self.template, self.document_1.get_merge_fields()))
        self.document_1.merge(test_name=student_name,
                              test_type=student_type,
                              test_number=room_number,
                              question_1=question_1,
                              question_2=question_2,
                              question_3=question_3,
                              question_4=question_4,
                              question_5=question_5)
        # 普通 word 文档生成
        self.document_1.write(self.path + '\paper-' + student_number + '.docx')

    def born_pdf(self, student_number):
        pythoncom.CoInitialize()
        in_file = self.path + '\paper-' + student_number + '.docx'
        out_file = self.pdf + '\paper-' + student_number + '.pdf'
        print(in_file)
        print(out_file)
        # 创建COM对象
        # try:
        word = client.DispatchEx("Word.Application")
        if os.path.exists(out_file):
            os.remove(out_file)
        doc = word.Documents.Open(in_file, ReadOnly=1)
        doc.SaveAs(out_file, FileFormat=17)
        doc.Close()
Example #32
0
def function():
    #获得参数
    energygrps_get = str(inp3.get())
    rlist_get = str(inp4.get())
    rcoulomb_get = str(inp5.get())
    rvdw_get = str(inp5.get())
    #作一步计算
    #加载模板
    template = "./model/EMmdp.docx"

    document = MailMerge(template)
    print("Fields included in {}: {}".format(template,
                                             document.get_merge_fields()))
    document.merge(
        energygrps=energygrps_get,
        rlist=rlist_get,  #这个要看模型
        rcoulomb=rcoulomb_get,  #这个为cutoff 参数值。rvdw是LJ或buckingham的阈值。默认为1.0 nm
        rvdw=rvdw_get,  #这个为cutoff 参数值。rvdw是LJ或buckingham的阈值。默认为1.0 nm
    )
    document.write('EM-MdpOut.docx')
    path = "EM-MdpOut.docx"
    doc = Document(path)
    print("----------生成模板中-----------")
    #批量写入到mdp中
    with open("EM-MdpOut.mdp", "w") as file:
        for paragraph in doc.paragraphs:
            print(paragraph.text)
            file.write(paragraph.text + "\n")
    #别嘴臭我,我真的只会if和else........
    if energygrps_get == '':
        answer = tkinter.messagebox.askokcancel('警告', 'energygrps_get没有填写')
    if rlist_get == '':
        answer = tkinter.messagebox.askokcancel('警告', 'rlist没有填写')
    if rcoulomb_get == '':
        answer = tkinter.messagebox.askokcancel('警告', 'rcoulomb没有填写')
    if rvdw_get == '':
        answer = tkinter.messagebox.askokcancel('警告', 'rvdw没有填写')
    else:
        answer = tkinter.messagebox.askokcancel('消息', '模板文件生成成功')
Example #33
0
    def WriteAssignment(project_name, teacher, idofcourse, idofassignment):
        fullname = "Andrew Maddox"
        schoolname = "University of advancing technology"
        fullname = fullname.title()
        schoolname = schoolname.title()
        print("-" * 45)
        print("Creator - Andrew Maddox")
        print("This is my project management script")
        print("-" * 45)

        template = "Template.docx"

        document = MailMerge(template)
        print(document.get_merge_fields())

        document.merge(
            AssignmentID=f'{idofassignment}',
            IndividualName=f'{fullname}',
            AssignmentName=f'{project_name}',
            Teacher=f'{teacher}',
            ClassID=f'{idofcourse}',)

        document.write(f'{project_name}.docx')
        popupmsg("Document Created!!")
Example #34
0
def generate_doc(template, data, output):
  document = MailMerge((template))
  document.merge(**data)
  print(document.get_merge_fields())
  document.write(output)
Example #35
0
# https://pbpython.com/python-word-template.html

# conda install -U lxml 
# pip install -U docx-mailmerge

from __future__ import print_function
from mailmerge import MailMerge
from datetime import date

template = "demo.docx"

document = MailMerge(template)
print(document.get_merge_fields())

document.merge(date = '10/01/1997',
                to_name = 'Dishant R. Raut',
                sub = 'Submission of Annual Returns in Form XXV under Gujarat Contract Labour (Regulation and Abolition Rules)',
                comp_name = 'Onion King',
                comp_add = 'Unit No. 1-7 on Gr. & First Floor, Shreeji One, Near. Gurudwara, Indira Gandhi Road, Jamnagar, Gujarat - 361001',
                Add_l1 = 'Diamond Market, 2nd floor,',
                Add_l2 = 'near Amber Cinema,',
                loc = 'Jamnagar',
                pincode = '361001')
document.write(f'MM_{comp_name}.docx')
def get_merge_fields():
    template = "remittance_template.docx"
    document = MailMerge(template)
    print(document.get_merge_fields())
    time.sleep(1)
    return document
Example #37
0
def generate(template_path, event_id, work_address, addressed_to,
             residential_address, passport_name, passport_no,
             passport_issued_by, invitation_letter_sent_at, to_date, from_date,
             country_of_residence, nationality, date_of_birth, email,
             user_title, firstname, lastname, bringing_poster, expiry_date):

    check_values(template_path, event_id, work_address, addressed_to,
                 residential_address, passport_name, passport_no,
                 passport_issued_by, invitation_letter_sent_at, to_date,
                 from_date, country_of_residence, nationality, date_of_birth,
                 email, user_title, firstname, lastname, bringing_poster,
                 expiry_date)

    # Path to store the template locally of merged and unmerged
    template = 'app/invitationletter/template/tmp.docx'
    template_merged = 'app/invitationletter/template/template.docx'

    download_blob(bucket_name=GCP_BUCKET_NAME,
                  source_blob_name=template_path,
                  destination_file_name=template)

    if not os.path.exists(template):
        return errors.TEMPLATE_NOT_FOUND

    document = MailMerge(template)
    LOGGER.debug("merge-fields.... {} .".format(document.get_merge_fields()))
    document.merge(TITLE=user_title,
                   FIRSTNAME=firstname,
                   LASTNAME=lastname,
                   WORK_ADDRESS=work_address.decode('utf-8'),
                   ADDRESSED_TO=addressed_to.decode('utf-8'),
                   RESIDENTIAL_ADDRESS=residential_address.decode('utf-8'),
                   PASSPORT_NAME=passport_name.decode('utf-8'),
                   PASSPORT_NO=passport_no.decode('utf-8'),
                   ISSUED_BY=passport_issued_by.decode('utf-8'),
                   EXPIRY_DATE=expiry_date,
                   ACCOMODATION_END_DATE=to_date,
                   ACCOMODATION_START_DATE=from_date,
                   COUNTRY_OF_RESIDENCE=country_of_residence.decode('utf-8'),
                   NATIONALITY=nationality,
                   DATE_OF_BIRTH=date_of_birth,
                   INVITATION_LETTER_SENT_AT=invitation_letter_sent_at,
                   BRINGING_POSTER=bringing_poster)

    document.write(template_merged)

    # Conversion
    template_pdf = 'app/invitationletter/letter/template.pdf'
    if os.path.exists(template_pdf):
        os.remove(template_pdf)
    success = pdfconvertor.convert_to(folder='app/invitationletter/letter',
                                      source=template_merged,
                                      output=template_pdf)
    if not success:
        return errors.CREATING_INVITATION_FAILED

    event = db.session.query(Event).get(event_id)
    if not event:
        return errors.EVENT_NOT_FOUND

    subject = "Invitation Letter for " + event.name

    try:
        emailer.send_mail(recipient=email,
                          subject=subject,
                          body_text=INVITATION_EMAIL_BODY.format(
                              user_title=user_title,
                              first_name=firstname,
                              last_name=lastname),
                          file_name="InvitationLetter.pdf",
                          file_path=template_pdf)

        LOGGER.debug('successfully sent email...')
        return True
    except ValueError:
        LOGGER.debug('Did not send email...')
        return False

    return False
        ### Reorder label export sheet columns (used to line up withe Excel Macro, want to keep it just in case)
        label_export_sheet = label_export_sheet[[
            'ProjectName', 'ProjectNumber', 'SampleID', 'Container',
            'Preservative', 'BottleNumber', 'NumberOfBottles', 'AnalysisSuite',
            'SampleType', 'Matrix', 'Sample Date', 'Sample Time'
        ]]

        #########################################
        #### Mail Merge HERE
        document = MailMerge(
            template_dir +
            template_file)  ## Opens template file downloaded from GitHub above

        ## Check which merge fields are present, this is where the label data goes into
        print document.get_merge_fields()
        get_fields = document.get_merge_fields()

        ## Fields that are required for the label:
        merge_fields = label_export_sheet[[
            'NumberOfBottles', 'Container', 'ProjectName', 'AnalysisSuite',
            'SampleID', 'BottleNumber', 'Preservative', 'Sample Date',
            'Sample Time'
        ]]

        ## build list of data for each label
        row_list = []
        for row in merge_fields.iterrows():
            row_list.append({
                'NumberOfBottles': row[1]['NumberOfBottles'],
                'Container': row[1]['Container'],
Example #39
0
def findGP(name, gpList):
    for row in gpList:
        print(row)
        if (row[2] == name):
            return row

    return None


# ------------------------- Main ----------------------------

gpListFile = 'addresses.csv'
template = "gp_template.docx"
document = MailMerge(template)
print("Fields:")
fields_set = document.get_merge_fields()
print(fields_set)

# get cmd args
argv = sys.argv
gpSurname = argv[1]
gpSurgery = argv[2]
ptTitle = argv[3]
ptFirstName = argv[4]
ptSurname = argv[5]
patientDOB = argv[6]

gpList = getGPList(gpListFile)
gpInfo = findGP(gpSurname, gpList)

print("ARGS, GP LIST AND GP INFO")
Example #40
0
from __future__ import print_function
from datetime import date
from mailmerge import MailMerge
import xlrd

#name of the contract template in the same folder
contract_template = "template.docx"

#name of the exel sheet and worksheet containing the data
workbook = xlrd.open_workbook("Excel.xlsx")
worksheet = workbook.sheet_by_name("information")

contract = MailMerge(contract_template)

print(contract.get_merge_fields())

#tokens are the names of the tokens in the worksheets
token_one = worksheet.cell_value(1, 1)
token_two = worksheet.cell_value(2, 1)

#run everything
contract.merge(Test=man_name_short)
contract.write("merged_contract.docx")
 def test(self):
     document = MailMerge(path.join(path.dirname(__file__), 'test_issue8.docx'))
     self.assertEqual(document.get_merge_fields(), {'testfield'})