Exemple #1
0
    def test_sharedStrings_text(self):
        xml_base = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n' \
                   '<sst uniqueCount="{sharedString_len}" count="{sharedString_len}" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">\r\n' \
                   '{many_tag_si}\r\n' \
                   '</sst>'
        xml_tag_si = '<si><t {space_preserve}>{val}</t></si>\r\n'

        many_tag_si = xml_tag_si.format(space_preserve='',val='text1') + \
                      xml_tag_si.format(space_preserve='',val='text2') + \
                      xml_tag_si.format(space_preserve='xml:space="preserve"',val=' text3') + \
                      xml_tag_si.format(space_preserve='',val='text4') + \
                      xml_tag_si.format(space_preserve='xml:space="preserve"',val='text5 ') + \
                      xml_tag_si.format(space_preserve='xml:space="preserve"',val=' text6 ')

        db = xl.Database()
        db.add_ws('Sheet1', {'A1': {'v': 'text1', 'f': '', 's': ''},
                             'A2': {'v': 'text2', 'f': '', 's': ''},
                             'A3': {'v': ' text3', 'f': '', 's': ''},
                             'A6': {'v': 'text4', 'f': '', 's': ''},
                             })

        db.add_ws('Sheet2', {'A4': {'v': 'text5 ', 'f': '', 's': ''},
                             'A5': {'v': ' text6 ', 'f': '', 's': ''},
                             'A6': {'v': 'text4', 'f': '', 's': ''},
                             })

        # process the sharedStrings, see dev note why this is done this way inside new_worksheet_text
        _ = xl.writexl_new_worksheet_text(db, 'Sheet1')
        _ = xl.writexl_new_worksheet_text(db, 'Sheet2')

        self.assertEqual(xl.writexl_new_sharedStrings_text(db), xml_base.format(sharedString_len=6 ,many_tag_si=many_tag_si))
Exemple #2
0
    def test_worksheet_text(self):
        xml_base = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n' \
                   '<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac xr xr2 xr3" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns:xr="http://schemas.microsoft.com/office/spreadsheetml/2014/revision" xmlns:xr2="http://schemas.microsoft.com/office/spreadsheetml/2015/revision2" xmlns:xr3="http://schemas.microsoft.com/office/spreadsheetml/2016/revision3" xr:uid="{uid}">\r\n' \
                   '<dimension ref="{sizeAddress}"/>\r\n' \
                   '<sheetViews>\r\n' \
                   '<sheetView tabSelected="1" workbookViewId="0"/>\r\n' \
                   '</sheetViews>\r\n' \
                   '<sheetFormatPr defaultRowHeight="15" x14ac:dyDescent="0.25"/>\r\n' \
                   '<sheetData>\r\n' \
                   '{many_tag_row}\r\n' \
                   '</sheetData>\r\n' \
                   '<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>\r\n' \
                   '</worksheet>'

        xml_tag_row = '<row r="{row_num}" x14ac:dyDescent="0.25" spans="1:{num_of_cr_tags}">{many_tag_cr}</row>\r\n'
        xml_tag_cr = '<c r="{address}" {str_option}>{tag_formula}<v>{val}</v></c>'

        # test all input types
        many_tag_cr_row1 = xml_tag_cr.format(address='A1', str_option='', tag_formula='', val=1) + \
                           xml_tag_cr.format(address='B1', str_option='t="s"', tag_formula='', val=0) + \
                           '<c r="{address}">{tag_formula}</c>'.format(address='C1', tag_formula='<f>A1+2</f>') + \
                           xml_tag_cr.format(address='D1', str_option='t="s"', tag_formula='', val=1)
        # test scarce, and repeat text value
        many_tag_cr_row3 = xml_tag_cr.format(address='A3', str_option='t="s"', tag_formula='', val=0) + \
                           xml_tag_cr.format(address='C3', str_option='t="s"', tag_formula='', val=2)

        many_tag_row = xml_tag_row.format(row_num=1,num_of_cr_tags=4,many_tag_cr=many_tag_cr_row1) + \
                       xml_tag_row.format(row_num=3,num_of_cr_tags=2,many_tag_cr=many_tag_cr_row3)

        uid = '2C7EE24B-C535-494D-AA97-0A61EE84BA40'
        sizeAddress = 'A1:D3'

        db = xl.Database()
        db.add_ws('Sheet1', {})
        db.ws('Sheet1').update_address('A1', 1)
        db.ws('Sheet1').update_address('B1', 'text1')
        db.ws('Sheet1').update_address('C1', '=A1+2')
        db.ws('Sheet1').update_address('D1', 'B1&"_"&"two"')
        db.ws('Sheet1').update_address('A3', 'text1')
        db.ws('Sheet1').update_address('C3', 'text2')

        self.assertEqual(
            xl.writexl_new_worksheet_text(db, 'Sheet1'),
            xml_base.format(sizeAddress=sizeAddress,
                            uid=uid,
                            many_tag_row=many_tag_row))