Exemple #1
0
 def test_parsing1(self):
     html = """
             <table class='sheet' data-name='First sheet'>
                 <tr>
                     <td>1</td>
                     <td>2</td>
                 </tr>
                 <tr>
                     <td>3</td>
                     <td>4</td>
                 </tr>
             </table>"""
     parser = InputParser(html)
     table = parser.parse()
     self.assertIsInstance(table, Table)
     self.assertEqual(len(table.sheets), 1)
     sheet = table.sheets[0]
     self.assertIsInstance(sheet, Sheet)
     self.assertEqual(len(sheet.rows), 2)
     i = 1
     for row in sheet:  ## sheet.rows
         self.assertIsInstance(row, Row)
         self.assertEqual(len(row.cells), 2)
         for cell in row:  ## row.cells
             self.assertIsInstance(cell, Cell)
             self.assertIsInstance(cell.value, unicode)
             self.assertEqual(cell.value, unicode(i))
             i += 1
Exemple #2
0
 def test_header(self):
     html = """
             <table class='sheet' data-name='First sheet'>
                 <thead>
                     <tr>
                         <th>First column</th>
                         <th>Second column</th>
                     </tr>
                 </thead>
                 <tbody>
                     <tr>
                         <td>1</td>
                         <td data-type='number'>2</td>
                     </tr>
                     <tr>
                         <td data-type='number'>3</td>
                         <td data-type='date'>2013-12-31</td>
                     </tr>
                 </tbody>
             </table>"""
     parser = InputParser(html)
     table = parser.parse()
     sheet = table.sheets[0]
     self.assertEqual(len(sheet.rows), 3)
     self.assertEqual(sheet.rows[0].is_header, True)
     table.to_workbook('/tmp/header.xlsx')
 def test_header(self):
     html = """
             <table class='sheet' data-name='First sheet'>
                 <thead>
                     <tr>
                         <th>First column</th>
                         <th>Second column</th>
                     </tr>
                 </thead>
                 <tbody>
                     <tr>
                         <td>1</td>
                         <td data-type='number'>2</td>
                     </tr>
                     <tr>
                         <td data-type='number'>3</td>
                         <td data-type='date'>2013-12-31</td>
                     </tr>
                 </tbody>
             </table>"""
     parser = InputParser(html)
     table = parser.parse()
     sheet = table.sheets[0]
     self.assertEqual(len(sheet.rows), 3)
     self.assertEqual(sheet.rows[0].is_header, True)
     table.to_workbook('/tmp/header.xlsx')
 def test_parsing1(self):
     html = """
             <table class='sheet' data-name='First sheet'>
                 <tr>
                     <td>1</td>
                     <td>2</td>
                 </tr>
                 <tr>
                     <td>3</td>
                     <td>4</td>
                 </tr>
             </table>"""
     parser = InputParser(html)
     table = parser.parse()
     self.assertIsInstance(table, Table)
     self.assertEqual(len(table.sheets), 1)
     sheet = table.sheets[0]
     self.assertIsInstance(sheet, Sheet)
     self.assertEqual(len(sheet.rows), 2)
     i = 1
     for row in sheet: ## sheet.rows
         self.assertIsInstance(row, Row)
         self.assertEqual(len(row.cells), 2)
         for cell in row: ## row.cells
             self.assertIsInstance(cell, Cell)
             self.assertIsInstance(cell.value, unicode)
             self.assertEqual(cell.value, unicode(i))
             i += 1
Exemple #5
0
 def test_styling1(self):
     html = """
             <html>
             <head>
                 <style>
                     td { width: 3cm; font: 15px Arial, serif; }
                     tr.first td { vertical-align: middle; }
                 </style>
             </head>
             <body>
                 <table class='sheet' data-name='First sheet'>
                     <tr style="height: 30px" class="first">
                         <td style="background-color: #eee; font-weight: bold;">1</td>
                         <td style="font-size: 10px; font-style: italic; color: red;">2</td>
                     </tr>
                     <tr>
                         <td style="text-align: center;">3</td>
                         <td style="border: 2px solid blue;">4</td>
                     </tr>
                     <tr>
                         <td colspan=2>asdf</td>
                     </tr>
                 </table>
             </body>
             </html>"""
     html = generate_test_html(html)
     parser = InputParser(html)
     table = parser.parse()
     table.to_workbook('/tmp/proba.xlsx')
Exemple #6
0
 def test_output(self):
     ### TODO: data-type default in header?
     html = """
             <table class='sheet' data-name='First sheet'>
                 <tr>
                     <td>1</td>
                     <td data-type='number'>2</td>
                 </tr>
                 <tr>
                     <td data-type='number'>3</td>
                     <td data-type='date'>2013-12-31</td>
                 </tr>
             </table>"""
     parser = InputParser(html)
     table = parser.parse()
     table.to_workbook('/tmp/proba.xlsx')
 def test_output(self):
     ### TODO: data-type default in header?
     html = """
             <table class='sheet' data-name='First sheet'>
                 <tr>
                     <td>1</td>
                     <td data-type='number'>2</td>
                 </tr>
                 <tr>
                     <td data-type='number'>3</td>
                     <td data-type='date'>2013-12-31</td>
                 </tr>
             </table>"""
     parser = InputParser(html)
     table = parser.parse()
     table.to_workbook('/tmp/proba.xlsx')