예제 #1
0
def spreadsheet_to_text(indoc, outdoc):
    inbody = indoc.get_body()
    outbody = outdoc.get_body()
    # Copy tables
    for intable in inbody.get_tables():
        # clone/rstrip the table
        clone = intable.clone()
        clone.rstrip(aggressive=True)
        # Skip empty table
        if clone.get_size() == (0, 0):
            continue
        # At least OOo Writer doesn't like formulas referencing merged
        # cells, so expand
        outtable = odf_create_table(clone.get_name(),
                style=clone.get_style())
        # Columns
        for column in clone.traverse_columns():
            outtable.append(column)
        # Rows
        for inrow in clone.traverse():
            outrow = odf_create_row(style=inrow.get_style())
            # Cells
            for cell in inrow.traverse():
                # Formula
                formula = cell.get_formula()
                if formula is not None:
                    if formula.startswith('oooc:'):
                        formula = oooc_to_ooow(formula)
                    else:
                        # Found an OpenFormula test case
                        raise NotImplementedError, formula
                    cell.set_formula(formula)
                outrow.append(cell)
            outtable.append_row(outrow)
        outbody.append(outtable)
        # Separate tables with an empty line
        outbody.append(odf_create_paragraph())
    # Copy styles
    for family in ('table', 'table-column', 'table-row', 'table-cell'):
        for style in indoc.get_styles(family=family):
            automatic = (style.get_parent().get_tag()
                    == 'office:automatic-styles')
            default = style.get_tag() == 'style:default-style'
            outdoc.insert_style(style, automatic=automatic,
                    default=default)
예제 #2
0
 def test_addition_sum(self):
     formula = "oooc:=[.A2]-[.A3]+SUM([.B2:.B4])*[.D4]"
     excepted = "ooow:<A2>-<A3>+sum <B2:B4>*<D4>"
     self.assertEqual(oooc_to_ooow(formula), excepted)
예제 #3
0
 def test_sum(self):
     formula = "oooc:=SUM([.B2:.B4])"
     excepted = "ooow:sum <B2:B4>"
     self.assertEqual(oooc_to_ooow(formula), excepted)
예제 #4
0
 def test_addition(self):
     formula = "oooc:=[.A2]+[.A3]"
     excepted = "ooow:<A2>+<A3>"
     self.assertEqual(oooc_to_ooow(formula), excepted)
예제 #5
0
 def test_addition_sum(self):
     formula = "oooc:=[.A2]-[.A3]+SUM([.B2:.B4])*[.D4]"
     excepted = "ooow:<A2>-<A3>+sum <B2:B4>*<D4>"
     self.assertEqual(oooc_to_ooow(formula), excepted)
예제 #6
0
 def test_sum(self):
     formula = "oooc:=SUM([.B2:.B4])"
     excepted = "ooow:sum <B2:B4>"
     self.assertEqual(oooc_to_ooow(formula), excepted)
예제 #7
0
 def test_addition(self):
     formula = "oooc:=[.A2]+[.A3]"
     excepted = "ooow:<A2>+<A3>"
     self.assertEqual(oooc_to_ooow(formula), excepted)