Esempio n. 1
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
Esempio n. 2
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
    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)
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_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())
    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())
Esempio n. 9
0
    def apply_mailmerge(self, context, filename="example.docx"):
        # Return a django request response with a docx download.
        docx = StringIO()

        mailmerge = MailMerge(self.get_full_path())
        mailmerge.merge(context)
        mailmerge.write(docx)
        mailmerge.close()

        # return response
        docx.seek(0)
        response = HttpResponse(docx)
        response['Content-Disposition'] = 'attachment; filename={}'.format(filename)
        response['Content-Type'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
        return response
    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())
    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())
def create_folder(df):
    df_1 = df[['Provider_Fax', 'Organization_Name']]
    df_1 = df_1.drop_duplicates()
    templatename = 'D:Patient Reques.docx'
    main_path = 'D:'

    for index, row in df_1.iterrows():

        # prepare the folder name
        full_folder_path = main_path + str(
            row['Organization_Name']) + '_' + str(row['Provider_Fax'])

        #create the folder
        os.mkdir(full_folder_path)

        #Copy the provider letter to folders
        #shutil.copy(provider_letter_file, full_folder_path)

        #create the excel file inside the folder
        df_2 = df.loc[(df['Provider_Fax'] == row['Provider_Fax'])
                      & (df['Organization_Name'] == row['Organization_Name'])]
        df_2 = df_2.applymap(str)
        excel_folderpath = full_folder_path + '/' + str(
            row['Organization_Name']) + '_' + str(
                row['Provider_Fax']) + '.xlsx'
        writer = pd.ExcelWriter(excel_folderpath)
        df_2.to_excel(writer, index=False)
        writer.save()

        #look for template file Prepare the MailMerge File
        document = MailMerge(templatename)
        src = excel_folderpath
        book = xlrd.open_workbook(src)
        work_sheet = book.sheet_by_index(0)
        finalList = []
        headers = []
        num_rows = work_sheet.nrows
        current_row = 0
        while current_row < num_rows:
            dictVal = dict()
            if (current_row == 0):
                for col in range(work_sheet.ncols):
                    headers.append(work_sheet.cell_value(current_row, col))
            else:
                for col in range(work_sheet.ncols):
                    dictVal.update({
                        headers[col]:
                        work_sheet.cell_value(current_row, col)
                    })
            if (current_row != 0):
                finalList.append(dictVal)
            current_row += 1
        document.merge_pages(finalList)
        document.write(full_folder_path + '/' + str(row['Organization_Name']) +
                       '_' + str(row['Provider_Fax']) + '.docx')

        in_file = os.path.abspath(full_folder_path + '/' +
                                  str(row['Organization_Name']) + '_' +
                                  str(row['Provider_Fax']) + '.docx')
        out_file = os.path.abspath('D:' + str(row['Organization_Name']) + '_' +
                                   str(row['Provider_Fax']) + '.pdf')
        create_pdf(in_file, out_file)
Esempio n. 14
0
word_contract_folder = '/Users/haris/Documents/PowerMarket Docs/Green Street/Catlin/Contracts Work/Altice Contracts (Populated)/Word/'
pdf_contract_folder = '/Users/haris/Documents/PowerMarket Docs/Green Street/Catlin/Contracts Work/Altice Contracts (Populated)/PDF/'

for ind, row in xl_file.iterrows():
    # print(str(row['Zip_1']))
    street = str(row['Address'])
    city = str(row['City'])
    zip = str(row['Zip'])
    alloc = str('{0:.3%}'.format(row['% Allocation']))
    kw = str(row['System size (kW)'])

    print(street, " ", city, " ", zip, " ", alloc, " ", kw)

    document = MailMerge(template)
    document.merge(Street=street,
                   City=city,
                   Zip=zip,
                   allocation=alloc,
                   sysSize=kw)

    word_contract_name = '/Users/haris/Documents/PowerMarket Docs/Green Street/Catlin/Contracts Work/Altice Contracts (Populated)/Word/Catlin Solar 1 LLC GSPP Subscriber Agreement (Altice ' + str(
        row['Utility Account']) + ').docx'
    pdf_contract_name = '/Users/haris/Documents/PowerMarket Docs/Green Street/Catlin/Contracts Work/Altice Contracts (Populated)/PDF/Catlin Solar 1 LLC GSPP Subscriber Agreement (Altice ' + str(
        row['Utility Account']) + ').pdf'

    document.write(word_contract_name)
    convert(word_contract_name, pdf_contract_name)

# convert(word_contract_folder, pdf_contract_folder)
Esempio n. 15
0
		SELECT barang.`NAMABARANG`, barang.`KODEBARANG`, barang.`JUMLAHBARANG`, barang.`HARGABARANG`,barang.`TANGGALMASUK`, kondisi.`NAMAKONDISI`, merk.`NAMAMERK`, sumber.`NAMASUMBER`, lokasi.`NAMALOKASI` 
		FROM barang INNER JOIN kondisi ON kondisi.`IDKONDISI` = barang.`IDKONDISI`
		INNER JOIN merk ON merk.`IDMERK` = barang.`IDMERK` 
		INNER JOIN sumber ON sumber.`IDSUMBER` = barang.`IDSUMBER` 
		INNER JOIN lokasi ON lokasi.`IDLOKASI` = barang.`IDLOKASI` WHERE barang.IDBARANG =''' + str(nama_barang) +  " GROUP BY barang.`IDBARANG`"
	#print sql
	cur.execute(sql)

	data = []
	document = MailMerge(path+'LabelSDMI1.docx')
	for row in cur.fetchall():
		i = row[2]
		for x in range(i):
			temp = {}
			temp['tahun'] = str(row[4].year)
			temp['asal_dana']		= row[7]
			temp['nama_barang']		= row[0]
			temp['no_barang']		= row[1]
			temp['lokasi'] = row[8]
			temp['no'] = str(x+1)
			data.append(temp)

	document.merge_rows('no_barang', data)
	document.write(path+nama_file + '.docx')

cur.close()
db.close()

end = time.time()
elapsed = end - start
print str(elapsed) + " detik"
Esempio n. 16
0
    dict = {}
    if os.path.exists(sys_info_file):
        for line in open(sys_info_file):
            list = line.strip('\n').split("===")
            dict[list[0]] = list[1].decode('utf-8')
    sysname = dict.has_key('sysname') and dict['sysname'] or 'nono '
    document1 = MailMerge(template1)
    print("Fields included in {}:{}".format(template1,
                                            document1.get_merge_fields()))
    document1.merge(sysname=sysname,
                    author=dict.has_key('author') and dict['author'] or ' ',
                    level1=dict.has_key('level1') and dict['level1'] or ' ',
                    level2=dict.has_key('level2') and dict['level2'] or ' ',
                    rto=dict.has_key('rto') and dict['rto'] or ' ',
                    rpo=dict.has_key('rpo') and dict['rpo'] or ' ')
    document1.write(('./output/' + sysname + u'系统应急预案.docx').encode('gbk'))

    document2 = MailMerge(template2)
    print("Fields included in {}:{}".format(template2,
                                            document2.get_merge_fields()))
    document2.merge(sysname=sysname,
                    author=dict.has_key('author') and dict['author'] or ' ',
                    summary=dict.has_key('summary') and dict['summary'] or ' ')
    document2.merge_rows('col1', [{
        'col1': 'aa',
        'col2': 'ab',
        'col3': 'ac'
    }, {
        'col1': 'ba',
        'col2': 'bb',
        'col3': 'bc'
Esempio n. 17
0
 def merge_file_fields(self, doc_path, inserted_fields, filename):
     dict = inserted_fields
     document = MailMerge(doc_path)
     document.merge_pages([dict])
     document.write(filename)
     return filename
Esempio n. 18
0
#print bibList.items()
df=pd.DataFrame(bibList,index=[0])
print df.head()

df.to_csv('PythonExport.csv', sep=',')

from mailmerge import MailMerge
from datetime import date

df=pd.read_csv('PythonExport.csv')
print(df.iloc[0,1])
template = "123.docx"
document = MailMerge(template)
print(document.get_merge_fields())
di={"Name":"Sherni"}
document.merge(
    status='Gold',
    city='Springfield',
    phone_number=df.iloc[0,2],
    Business=df.iloc[0,1],
    zip=df.iloc[0,3],
    purchases=df.iloc[0,4],
    shipping_limit=df.iloc[0,5],
    state=df.iloc[0,6],
    address='1234 Main Street',
    date='{:%d-%b-%Y}'.format(date.today()),
    discount='5%',
    recipient="sdfs")

document.write('test-outpufinalt2.docx')
# plan  to dump data in a file
Esempio n. 19
0
def generatepdf():
    if not request.json:
        abort(400)
    root_directory = os.path.dirname(os.path.dirname(__file__))
    #Fetch Required Attributes From Request
    doc_format = request.json.get("DocFormat")
    cover_template_encoded = str(request.json.get("CoverTemplate"))
    footer_template_encoded = str(request.json.get("FooterTemplate"))

    #Generate a GUID For the Transaction
    docuuid = uuid.uuid4()

    #Set Template Paths
    merged_doc_path = os.path.join(root_directory,
                                   "./temp/" + str(docuuid) + '.docx')
    merged_pdf_path = os.path.join(root_directory,
                                   "./temp/" + str(docuuid) + '.pdf')
    cover_template_path = os.path.join(
        root_directory, "./temp/" + str(docuuid) + '_covertemplate.docx')
    cover_page_path = os.path.join(
        root_directory, "./temp/" + str(docuuid) + '_coverpage.docx')
    footer_template_path = os.path.join(
        root_directory, "./temp/" + str(docuuid) + '_footertemplate.docx')
    footer_page_path = os.path.join(
        root_directory, "./temp/" + str(docuuid) + '_footerpage.docx')
    input_files = [cover_page_path]
    #Write To Templates
    cover_template_decoded = base64.b64decode(cover_template_encoded)
    fh = open(cover_template_path, "wb")
    fh.write(cover_template_decoded)
    fh.close()

    footer_template_decoded = base64.b64decode(footer_template_encoded)
    fh = open(footer_template_path, "wb")
    fh.write(footer_template_decoded)
    fh.close()

    #Mail Merge Cover Letter and Footer
    cover_letter_template = MailMerge(cover_template_path)
    cover_letter_merge_fields = cover_letter_template.get_merge_fields()
    merge_field_values = {}
    for field in cover_letter_merge_fields:
        merge_field_values[field] = request.json.get(field, "")
    cover_letter_template.merge(**merge_field_values)
    cover_letter_template.write(cover_page_path)

    footer_letter_template = MailMerge(footer_template_path)
    footer_letter_merge_fields = footer_letter_template.get_merge_fields()
    merge_field_values = {}
    for field in footer_letter_merge_fields:
        merge_field_values[field] = request.json.get(field, "")
    footer_letter_template.merge(**merge_field_values)
    footer_letter_template.write(footer_page_path)

    quotedPlans = request.json.get("QuotedPlans", "")
    for i in range(len(quotedPlans)):
        quotedPlan = quotedPlans[i]

        sbc_template_encoded = str(quotedPlan.get("SBCTemplate"))
        sbc_template_path = os.path.join(
            root_directory,
            "./temp/" + str(docuuid) + '_' + str(i) + '_sbctemplate.docx')
        sbc_page_path = os.path.join(
            root_directory,
            "./temp/" + str(docuuid) + '_' + str(i) + '_sbcpage.docx')
        input_files.append(sbc_page_path)
        #Write to SBC Templates
        sbc_template_decoded = base64.b64decode(sbc_template_encoded)
        fh = open(sbc_template_path, "wb")
        fh.write(sbc_template_decoded)
        fh.close()
        #Mail Merge SBC Template
        sbc_letter_template = MailMerge(sbc_template_path)
        sbc_letter_merge_fields = sbc_letter_template.get_merge_fields()
        for field in sbc_letter_merge_fields:
            if (quotedPlan.get(field, "") != ""):
                merge_field_values[field] = quotedPlan.get(field, "")
        for field in sbc_letter_merge_fields:
            if (request.json.get(field, "") != ""):
                merge_field_values[field] = request.json.get(field, "")

        SBCs = quotedPlan.get("SBC", "")
        quote_line_census = quotedPlan.get("QuoteCensus", "")
        sbc_letter_template.merge_rows("Name", SBCs)
        sbc_letter_template.merge_rows("EmployeeName", quote_line_census)
        sbc_letter_template.merge(**merge_field_values)
        sbc_letter_template.write(sbc_page_path)

    #Append Footer
    input_files.append(footer_page_path)
    #Merge the Documents
    merged_document = combine_word_documents(input_files)
    merged_document.save(merged_doc_path)

    merged_doc_encoded = ""

    if (doc_format == 'pdf'):
        #Convert to PDF
        jar_file_path = os.path.abspath(
            os.path.join(root_directory,
                         "../bin/docs-to-pdf-converter-1.8.jar"))
        exec_args = " -i " + os.path.abspath(merged_doc_path)
        os.system("java -jar " + jar_file_path + exec_args)

        with open(merged_pdf_path, "rb") as pdf_file:
            merged_doc_encoded = base64.b64encode(pdf_file.read())
    else:
        with open(merged_doc_path, "rb") as docfile:
            merged_doc_encoded = base64.b64encode(docfile.read())

    pdfresponse = {
        'requestStatus': 'success',
        'documentid': str(docuuid),
        'documentname': str(docuuid) + '.' + doc_format,
        'document': merged_doc_encoded.decode("ascii")
    }
    return jsonify(pdfresponse), 200
Esempio n. 20
0
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())
Esempio n. 21
0
from mailmerge import MailMerge

doc = MailMerge("./Ex44_file/test.docx")
doc.merge(username="******", clazz="17计算机科学与技术")

doc.write("./Ex44_file/res.docx")
Esempio n. 22
0
from __future__ import print_function
from mailmerge import MailMerge
from contracts import ContractsBook

template = "test.docx"
contracts_book = ContractsBook('/data/data.xlsx')
data = contracts_book.data

for contract in data:
    msg = f'{contract["name"]} {contract["dob"]} {contract["address"]}'
    document = MailMerge(template)
    document.merge(name=contract["name"],
                   IS=contract["dob"],
                   date=contract["address"])
    document.write('testoutput' + contract["name"] + '.docx')

    print(msg)
Esempio n. 23
0
def home():
    conversation = request.files['audio']
    conversation.save('transcript.mp3')

    pdfTranscription = request.files['file']
    pdfTranscription.save('transcript.pdf')
    
    with pdfplumber.open(r'transcript.pdf') as pdf:
        all_text_data = []
        page_no = 0
        for page in pdf.pages:
            if page_no>0:
                all_text_data.extend(page.extract_text().split('\n')[1:-5])
            page_no+=1

    #found one occurance so removing   
    if "QUESTIONS AND ANSWERS" in all_text_data:
        all_text_data.remove("QUESTIONS AND ANSWERS")

    CORPORATE_PARTICIPANTS, CONFERENCE_CALL_PARTICIPANTS, start = processFirstpage(all_text_data)
    participants = CORPORATE_PARTICIPANTS+CONFERENCE_CALL_PARTICIPANTS+['Operator ']
    speakers,speeches = speakerSpeech(all_text_data[start:], participants)
    
    data1,emotion_array = speechToText('transcript.mp3')
    data = mockSpeechToText()

    prediction_array = []
    current_index = 0
    stable_index = 0
    repeat_count = 0

    for transciption in data:
        if transciption!="":
            y = compare(transciption.split(' '), speeches, current_index, stable_index)
            if y==current_index:
                repeat_count +=1
            else:
                repeat_count = 0

            if repeat_count==3:
                stable_index = current_index

            current_index = y
            prediction_array.append(current_index)
        else:
            prediction_array.append("*")
    
    data_array = []
    
    for index,sp in enumerate(prediction_array):
        if sp=='*':
            continue
        x = {}
        x['time'] = str(5*index)
        x['speaker'] = speakers[sp]
        x['speech'] = " ".join(speeches[sp])
        x['emotion'] = str(emotion_array[index])
        data_array.append(x)
  
    document = MailMerge('word_template.docx')
    document.merge_rows('time',data_array)
    document.write('test-output.docx')
    return "success"
Esempio n. 24
0
sheet = wb["Bookmarks"]
# find the last row for iteration / does not matter if not using for loop

max_column = sheet.max_column
# Can use pandas to dict to make dictionary to make easier for sending to docx
# using mailmerge
template = ("Report_template.docx")
document1 = MailMerge(template)

for i in range(2, max_column):
    document1.merge(NAME=str(sheet.cell(row=2, column=i).value),
                    SERVICENAME=str(sheet.cell(row=3, column=i).value),
                    BRANCH=str(sheet.cell(row=4, column=i).value),
                    Client_Name=str(sheet.cell(row=5, column=i).value),
                    Long_Name=str(sheet.cell(row=6, column=i).value),
                    Inspection_Period=str(sheet.cell(row=7, column=i).value),
                    R_Date=str(sheet.cell(row=8, column=i).value),
                    JBON_Project_Number=str(sheet.cell(row=9, column=i).value),
                    Short_Name=str(sheet.cell(row=10, column=i).value),
                    CompanyName=str(sheet.cell(row=11, column=i).value),
                    Prepared_by=str(sheet.cell(row=12, column=i).value),
                    Checked_by=str(sheet.cell(row=13, column=i).value),
                    Approved_by=str(sheet.cell(row=14, column=i).value))

# this writer will name the file for each row / if you have multiple customer files to send

# create new file based on the first line in the excel doc
document1.write("NewFile " + str(sheet.cell(row=1, column=1).value) + ".docx")
# use this line if you want constant name
# document1.write("new_file.docx")
Esempio n. 25
0
    def send():
        template="invoice1.docx"#to take  reference file
        f=open('count.txt','r')
        content=f.read()
        f.close()
        o=" "
        a=[0 for x in range(5)]
        d=[" " for x in range(5)]
        s=[" " for x in range(5)]
        flag=1

        
        if OrgName.get():
            o=OrgName.get()
        else:
            print("Organistaion is not provided")
            wam1=Label(data,text="Organisation name is compulsory",fg="red",font=('helvetica',8,'italic'),bg="white")
            wam1.place(x=500,y=220)
            flag=0


            

            
        if detail1.get() and amount1.get():
            try:
                a[0]=int(amount1.get())
            except ValueError:
                print("Enter Integer")
                wam2=Label(data,text="Please Enter a number",fg="red",font=('helvetica',8,'italic'),bg="white")
                wam2.place(x=700,y=420)
                flag=0
            d[0]=detail1.get()
            s[0]="1"
        else:
            print("Details are incomplete")
            wam3=Label(data,text="Please enter both the detail and amount",fg="red",font=('helvetica',8,'italic'),bg="white")
            wam3.place(x=350,y=420)
            flag=0


            

            

        if detail2.get() and amount2.get():
            try:
                a[1]=int(amount2.get())
            except ValueError:
                print("Enter Integer")
                wam4=Label(data,text="Please Enter a number",fg="red",font=('helvetica',8,'italic'),bg="white")
                wam4.place(x=700,y=470)
                flag=0
            d[1]=detail2.get()
            s[1]="2"
        elif detail2.get() or amount2.get():
            print("Details are incomplete")
            wam5=Label(data,text="Please enter both the detail and amount",fg="red",font=('helvetica',8,'italic'),bg="white")
            wam5.place(x=350,y=470)
            flag=0

            



        if detail3.get() and amount3.get():
            try:
                a[2]=int(amount3.get())
            except ValueError:
                print("Enter Integer")
                wam6=Label(data,text="Please Enter a number",fg="red",font=('helvetica',8,'italic'),bg="white")
                wam6.place(x=700,y=520)
                flag=0
            d[2]=detail3.get()
            s[2]="3"
        elif detail3.get() or amount3.get():
            print("Details are incomplete")
            wam7=Label(data,text="Please Enter both the detail and amount",fg="red",font=('helvetica',8,'italic'),bg="white")
            wam7.place(x=350,y=520)
            flag=0

            


        if detail4.get() and amount4.get():
            try:
                a[3]=int(amount4.get())
            except ValueError:
                print("Enter Integer")
                wam8=Label(data,text="Please Enter a number",fg="red",font=('helvetica',8,'italic'),bg="white")
                wam8.place(x=700,y=570)
                flag=0
            d[3]=detail4.get()
            s[3]="4"
        elif detail4.get() or amount4.get():
            print("Details are incomplete")
            wam9=Label(data,text="Please Enter both the detail and amount",fg="red",font=('helvetica',8,'italic'),bg="white")
            wam9.place(x=350,y=570)
            flag=0



        if detail5.get() and amount5.get():
            try:
                a[4]=int(amount5.get())
            except ValueError:
                print("Enter Integer")
                wam10=Label(data,text="Please Enter a number",fg="red",font=('helvetica',8,'italic'),bg="white")
                wam10.place(x=700,y=620)
                flag=0
            d[4]=detail5.get()
            s[4]="5"
        elif detail5.get() or amount5.get():
            print("Details are incomplete")
            wam11=Label(data,text="Please Enter both the detail and amount",fg="red",font=('helvetica',8,'italic'),bg="white")
            wam11.place(x=350,y=620)
            flag=0


        sumfig=a[0]+a[1]+a[2]+a[3]+a[4]
        b=inflect.engine().number_to_words(sumfig)
        for x in range(5):
            if a[x]==0:
              a[x]=" "
            
        
             


        if flag:# flag is a marker variable    
            document=MailMerge(template)
            document.merge(
            ino="00"+str(content),
            Dated='{:%d-%b-%y}'.format(date.today()),
            OrgName=o,
            GSTIN=Gst.get(),
            PANNO=Pan.get(),
            Addr=Address.get(),
            S1=s[0],
            S2=s[1],
            S3=s[2],
            S4=s[3],
            S5=s[4],
            Detail1=d[0],
            Detail2=d[1],
            Detail3=d[2],
            Detail4=d[3],
            Detail5=d[4],
            Amt1=str(a[0]),
            Amt2=str(a[1]),
            Amt3=str(a[2]),
            Amt4=str(a[3]),
            Amt5=str(a[4]),
            SumInFig=str(sumfig),
            AmtWords=b,)
            a="Inv_"+"00"+(content)+"_"+OrgName.get()+".docx"
            document.write(a)
            f=open('count.txt','w')
            f.write(str(int(content.strip())+1))
            f.close()
            ig=Label(data,text="Invoice Generated",font=14,fg='green')
            ig.place(x=410,y=700)
Esempio n. 26
0
from __future__ import print_function
from mailmerge import MailMerge
#from datetime import date

template = "template1.docx"

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

document.merge(position='senior partner position',
               typesOfWork='various things',
               field='November',
               connection='Brother',
               genderPronoun='he',
               person='Quinn Adams')

document.write('test-output.docx')
Esempio n. 27
0
from mailmerge import MailMerge
from datetime import date

template = "./template/word1_temp.docx"
template_rec = "./template/word1_rec_temp.docx"
# document = MailMerge(template)
document_Multi = MailMerge(template)
# print(document.get_merge_fields())

myDict = {22222: "222244444", 33333: "333366666"}
myList = []
for key in myDict:
    document = MailMerge(template)
    document.merge(cust_id=str(key), cust_name=myDict[key])
    myList.append({"cust_id": str(key), "cust_name": myDict[key]})
    document.write('./word/' + myDict[key] + '.docx')
# for key in myDict:
document_Multi.merge_pages(myList)
document_Multi.write('./word/combined.docx')

document_rec = MailMerge(template_rec)
document_rec.merge_rows('cust_id', myList)
document_rec.write('./word/combined_rec.docx')

document_test = MailMerge('./template/word1_test.docx')
print(document_test.get_merge_fields())
Esempio n. 28
0
from datetime import date
from docx2pdf import convert

template = "cover_letter_template.docx"

document = MailMerge(template)

# ask user for Company/Job details
company_name = input("Name of Company: ")
job_title = input("Job Title: ")
job_skill = input("Main Job Skill: ")

# replace all MailMerge values
document.merge(company=company_name,
               job=job_title,
               skill=job_skill,
               date='{:%B %d, %Y}'.format(date.today()))
outfile = f"{company_name} Cover Letter"

# write the merged version to a new document
document.write(outfile + ".docx")

#convert to pdf
convert(outfile + ".docx")

# move to appropriate folder in "Job Resources"
shutil.move(outfile + ".pdf",
            "C:\\Users\\harsh\\Desktop\\Job Resources\\Cover Letters")
shutil.move(outfile + ".docx",
            "C:\\Users\\harsh\\Desktop\\Job Resources\\Cover Letters\\docs")
Esempio n. 29
0
    template = "Prueba1.docx"
else:
    template = "Prueba5.docx"

if template == "Prueba1.docx":
    sentido = "desestim"
else:
    sentido = "estim total"

document = MailMerge(template)

document.merge(
        Actor=str(entry_var2.get()).upper(),
        Demandado=str(entry_var3.get()).title(),
        Fechaactainspeccion=entry_var4.get(),
        fecharesolucionrecargo=entry_var5.get(),
        articulosinfringidos=str(entry_var6.get()) + " de la LPRL",
        fechareclamacionprevia=entry_var7.get(),
        fecharesolucionreclamacionprevia=entry_var8.get(),
        pruebaspracticadas=" así como la " + str(entry_var9.get()),
        Año=entry_var12.get(),
        Número=entry_var11.get(),
        Enelpresentecaso=entry_var10.get())

if variable.get() == "Fuerza Mayor":
    document.merge(fortuitomayor1="por la fuerza mayor operada al tiempo del accidente", fortuitomayor2 = "sino que el hecho acaecido responde a un caso de fuerza mayor, esto es, un evento extraño al círculo o ámbito de la actividad del trabajador y de la empresa, que rompe el nexo de causalidad")
else:
    document.merge(fortuitomayor1="por su acaecimiento fortuito", fortuitomayor2 = "sino que el hecho acaecido responde a un caso fortuito, esto es, un hecho independiente de la voluntad del deudor de seguridad (la empresa), imprevisible e inevitable")

document.write('recargo prestaciones' + " " + entry_var11.get() + "-" + entry_var12.get() + " " + sentido + '.docx')
    {
        'index' : '0',
        'service_name' : 'Услуг Телефония',
        'total' : str(total_cdr)
    },
    {
        'index': '1',
        'service_name' : 'Услуг Netflow',
        'amount' : str(amount_netflow),
        'unit' : 'МБ',
        'total': str(total_netflow)
    }
]
document.merge_rows('index', servicesList)

# Chen thong tin tong hoa don
payment_total_without_tax = total_cdr + total_netflow
payment_total = round(payment_total_without_tax * TAX / 100, 2)
document.merge(
    payment_total_without_tax = str(payment_total_without_tax),
    tax = str(TAX) + ' %',
    payment_total = str(payment_total),
    service_count = str(len(servicesList))
)

document.write('invoice.docx')
print('processing...')
convert('invoice.docx')
os.remove('invoice.docx')
print('complete')
Esempio n. 31
0
sheet = wb.sheet_by_index(0)
sheet.cell_value(0, 0)

for row in range(sheet.nrows):
    value = sheet.row_values(row)
    template = 'UPDATED DX.docx'
    document = MailMerge(template)

    if str(int(value[1])) in Doctors.code:

        document.merge(DX=value[2],
                       DOS=value[3][1:],
                       doctor=Doctors.res[str(int((value[1])))],
                       invoice=str(int(value[0])),
                       patient=value[4],
                       DOB=value[5][1:],
                       code=str(int(value[1])))

        document.write('RESULT/' + str(int(value[1])) + '_' +
                       str(int(value[0])) + '.docx')
    else:
        document.merge(DX=value[2],
                       DOS=value[3][1:],
                       doctor='NOT FOUND',
                       invoice=str(int(value[0])),
                       patient=value[4],
                       DOB=value[5][1:],
                       code=str(int(value[1])))
        document.write('RESULT/NotFound/ERROR' + str(int(value[1])) + '_' +
                       str(int(value[0])) + '.docx')