예제 #1
0
 def test_odf_create_table_cell_style_all(self):
     border_left = make_table_cell_border_string(color='blue')
     border_right = make_table_cell_border_string(thick=60)
     style = odf_create_table_cell_style(
                             background_color='yellow',
                             color=(128,64,32),
                             border_left=border_left,
                             border_right=border_right)
     self.assertEqual(style.serialize(), ('<style:style '
         'style:family="table-cell"><style:table-cell-properties '
         'fo:border-top="none" fo:border-left="0.06pt solid #0000FF" '
         'fo:background-color="#FFFF00" '
         'fo:border-right="0.60pt solid #000000" fo:border-bottom="none"/>'
         '<style:text-properties fo:color="#804020"/></style:style>'))
예제 #2
0
 def test_odf_create_table_cell_style_all(self):
     border_left = make_table_cell_border_string(color='blue')
     border_right = make_table_cell_border_string(thick=60)
     style = odf_create_table_cell_style(background_color='yellow',
                                         color=(128, 64, 32),
                                         border_left=border_left,
                                         border_right=border_right)
     self.assertEqual(
         style.serialize(),
         ('<style:style '
          'style:family="table-cell"><style:table-cell-properties '
          'fo:border-top="none" fo:border-left="0.06pt solid #0000FF" '
          'fo:background-color="#FFFF00" '
          'fo:border-right="0.60pt solid #000000" fo:border-bottom="none"/>'
          '<style:text-properties fo:color="#804020"/></style:style>'))
예제 #3
0
 def test_odf_create_table_cell_style_top(self):
     border = make_table_cell_border_string()
     style = odf_create_table_cell_style(border_top=border)
     self.assertEqual(style.serialize(), ('<style:style '
         'style:family="table-cell"><style:table-cell-properties '
         'fo:border-top="0.06pt solid #000000" fo:border-left="none" '
         'fo:border-right="none" fo:border-bottom="none"/></style:style>'))
예제 #4
0
 def test_odf_create_table_cell_style(self):
     border = make_table_cell_border_string()
     style = odf_create_table_cell_style(border=border)
     self.assertEqual(
         style.serialize(),
         ('<style:style '
          'style:family="table-cell"><style:table-cell-properties '
          'fo:border="0.06pt solid #000000"/></style:style>'))
예제 #5
0
 def test_odf_create_table_cell_style_color(self):
     border = make_table_cell_border_string(color='blue')
     style = odf_create_table_cell_style(border=border, color='yellow')
     self.assertEqual(
         style.serialize(),
         ('<style:style '
          'style:family="table-cell"><style:table-cell-properties '
          'fo:border="0.06pt solid #0000FF"/><style:text-properties '
          'fo:color="#FFFF00"/></style:style>'))
예제 #6
0
 def test_odf_create_table_cell_style_bg(self):
     border = make_table_cell_border_string(color='blue')
     style = odf_create_table_cell_style(
                             border=border,
                             background_color='green')
     self.assertEqual(style.serialize(), ('<style:style '
         'style:family="table-cell"><style:table-cell-properties '
         'fo:border="0.06pt solid #0000FF" fo:background-color="#008000"/>'
         '</style:style>'))
예제 #7
0
 def test_odf_create_table_cell_style_top(self):
     border = make_table_cell_border_string()
     style = odf_create_table_cell_style(border_top=border)
     self.assertEqual(
         style.serialize(),
         ('<style:style '
          'style:family="table-cell"><style:table-cell-properties '
          'fo:border-top="0.06pt solid #000000" fo:border-left="none" '
          'fo:border-right="none" fo:border-bottom="none"/></style:style>'))
예제 #8
0
 def test_odf_create_table_cell_style_color(self):
     border = make_table_cell_border_string(color='blue')
     style = odf_create_table_cell_style(
                             border=border,
                             color='yellow')
     self.assertEqual(style.serialize(), ('<style:style '
         'style:family="table-cell"><style:table-cell-properties '
         'fo:border="0.06pt solid #0000FF"/><style:text-properties '
         'fo:color="#FFFF00"/></style:style>'))
예제 #9
0
 def test_odf_create_table_cell_style_bg(self):
     border = make_table_cell_border_string(color='blue')
     style = odf_create_table_cell_style(border=border,
                                         background_color='green')
     self.assertEqual(
         style.serialize(),
         ('<style:style '
          'style:family="table-cell"><style:table-cell-properties '
          'fo:border="0.06pt solid #0000FF" fo:background-color="#008000"/>'
          '</style:style>'))
예제 #10
0
def setup_document_styles(document):
    """ Setup all styles used in the document, after the setup
    the style can be used by its 'name' as X.set_style(stylename)

    example: cell.set_style(STYLE[TABLE_CELL_BASE])
    """

    doc_title_style = odf_create_style('paragraph', size='18', bold=True)
    STYLES[DOCUMENT_TITLE] = document.insert_style(style=doc_title_style,
                                                   default=True)

    # Setup base cell style
    border = make_table_cell_border_string(
        thick='0.03cm', color='black'
    )
    style = {
        'color': 'black',
        'background_color': (255, 255, 255),
        'border_right': border,
        'border_left': border,
        'border_bottom': border,
        'border_top': border
    }

    base_style = odf_create_table_cell_style(**style)
    STYLES[TABLE_CELL_BASE] = document.insert_style(
        style=base_style, automatic=True
    )

    # Setup colored cell styles (based on score)
    for color_val, color_rgb in COLORS.items():
        style['background_color'] = color_rgb

        _style = odf_create_table_cell_style(**style)
        _stylename = "{}{}".format(TABLE_CELL_AS_VALUE, color_val)
        STYLES[_stylename] = document.insert_style(
            style=_style,
            automatic=True
        )

    col_style = odf_create_style('table-column', width='3cm')
    STYLES[DESCR_COLUMN_WIDTH] = document.insert_style(
        style=col_style, automatic=True
    )
    row = odf_create_row()
    row.set_value(column - 1, u"Total with tax:")
    total *= (1 + tax_rate)
    cell = odf_create_cell()
    cell.set_value(total, text = u"%.2f €" % total,
                                currency = u"EUR", cell_type="float")
    row.set_cell(column, cell)
    row_number += 1
    table.set_row(row_number, row)
    # let merge some cells
    table.set_span((column -3, row_number, column -1, row_number), merge = True)

    # Let's add some style on first row
    border = make_table_cell_border_string(
                                thick = '0.03cm',
                                color = 'black'
                                )
    cell_style = odf_create_table_cell_style(
                                color = 'black',
                                background_color = (210, 210, 210),
                                border_right = border,
                                border_left = border,
                                border_bottom = border,
                                border_top = border,
                                )
    style_name = commercial.insert_style(style=cell_style, automatic=True)

    row = table.get_row(0)
    #for cell in row.get_cells(): #possible, but .traverse() is better
    for cell in row.traverse():
        cell.set_style(style_name)
예제 #12
0
 def test_border_bold2(self):
     expected = '0.30pt solid #000000'
     self.assertEqual(make_table_cell_border_string(thick=u"0.30pt"),
                      expected)
예제 #13
0
 def test_default_border(self):
     expected = '0.06pt solid #000000'
     self.assertEqual(make_table_cell_border_string(), expected)
예제 #14
0
 def test_border_color_tuple(self):
     expected = '0.06pt solid #808080'
     self.assertEqual(make_table_cell_border_string(color=(128,128,128)),
                      expected)
예제 #15
0
 def test_odf_create_table_cell_style(self):
     border = make_table_cell_border_string()
     style = odf_create_table_cell_style(border=border)
     self.assertEqual(style.serialize(), ('<style:style '
         'style:family="table-cell"><style:table-cell-properties '
         'fo:border="0.06pt solid #000000"/></style:style>'))
예제 #16
0
 def test_border_custom(self):
     expected = '0.1cm dotted #FF0000'
     self.assertEqual(make_table_cell_border_string(thick='0.1cm ',
                                                    line=' dotted',
                                                    color = '#FF0000 '),
                                                 expected)
예제 #17
0
 def test_border_color_name(self):
     expected = '0.06pt solid #D3D3D3'
     self.assertEqual(make_table_cell_border_string(color='lightgrey'),
                      expected)
예제 #18
0
 def test_border_bold2(self):
     expected = '0.30pt solid #000000'
     self.assertEqual(make_table_cell_border_string(thick=u"0.30pt"), expected)
예제 #19
0
 def test_border_int(self):
     expected = '0.06pt solid #000000'
     self.assertEqual(make_table_cell_border_string(thick=6), expected)
# Hello messages
print 'lpod installation test'
print ' Version           : %s' % __version__
print ' Installation path : %s' % __installation_path__
print
print 'Generating color chart in my_color_chart.ods ...'

document = odf_new_document('spreadsheet')
body = document.get_body()
table = odf_create_table(u'chart')

for y in xrange(0, 256, 8):
    row = odf_create_row()
    for x in xrange(0, 256, 32):
        cell_value = (x, y, (x + y) % 256)
        border_rl = make_table_cell_border_string(thick='0.20cm',
                                                  color='white')
        border_bt = make_table_cell_border_string(
            thick='0.80cm',
            color='white',
        )
        style = odf_create_table_cell_style(
            color='grey',
            background_color=cell_value,
            border_right=border_rl,
            border_left=border_rl,
            border_bottom=border_bt,
            border_top=border_bt,
        )
        name = document.insert_style(style=style, automatic=True)
        cell = odf_create_cell(value=rgb2hex(cell_value), style=name)
        row.append_cell(cell)
예제 #21
0
 def test_default_border(self):
     expected = '0.06pt solid #000000'
     self.assertEqual(make_table_cell_border_string(), expected)
print ' Version           : %s' %  __version__
print ' Installation path : %s' % __installation_path__
print
print 'Generating color chart in my_color_chart.ods ...'


document = odf_new_document('spreadsheet')
body = document.get_body()
table = odf_create_table(u'chart')

for y in xrange(0, 256, 8):
    row = odf_create_row()
    for x in xrange(0, 256, 32):
        cell_value = (x, y, (x+y) % 256 )
        border_rl = make_table_cell_border_string(
                                thick = '0.20cm',
                                color = 'white'
                                )
        border_bt = make_table_cell_border_string(
                                thick = '0.80cm',
                                color = 'white',
                                )
        style = odf_create_table_cell_style(
                                color = 'grey' ,
                                background_color = cell_value,
                                border_right = border_rl,
                                border_left = border_rl,
                                border_bottom = border_bt,
                                border_top = border_bt,
                                )
        name = document.insert_style(style=style, automatic=True)
        cell = odf_create_cell(value=rgb2hex(cell_value), style=name)
예제 #23
0
 def test_border_int(self):
     expected = '0.06pt solid #000000'
     self.assertEqual(make_table_cell_border_string(thick=6), expected)
예제 #24
0
 def test_border_custom(self):
     expected = '0.1cm dotted #FF0000'
     self.assertEqual(
         make_table_cell_border_string(thick='0.1cm ',
                                       line=' dotted',
                                       color='#FF0000 '), expected)
예제 #25
0
 def test_border_color_name(self):
     expected = '0.06pt solid #D3D3D3'
     self.assertEqual(make_table_cell_border_string(color='lightgrey'),
                      expected)
예제 #26
0
 def test_border_color_tuple(self):
     expected = '0.06pt solid #808080'
     self.assertEqual(make_table_cell_border_string(color=(128, 128, 128)),
                      expected)