Пример #1
0
def main():
    template = xw.Book.caller()
    template_path = template.fullname
    report_path = os.path.join(os.path.dirname(template.fullname), 'report.xlsx')

    # Matplotlib
    fig = Figure(figsize=(4, 3))
    ax = fig.add_subplot(111)
    ax.plot([1, 2, 3, 4, 5])

    # Pandas DataFrame
    perf_data = pd.DataFrame(index=['r1', 'r1'],
                             columns=['c0', 'c1'],
                             data=[[1., 2.], [3., 4.]])

    # Picture
    logo = Image(os.path.join(os.path.dirname(template.fullname), 'xlwings.jpg'))

    # Float
    perf = 0.12

    # Markdown

    mytext = dedent("""\
                # Q1 2021 Results

                The perfomance was {{ perf }}.
                This was due to the following points:

                * More sales
                * Cost cuts

                # Sales were strong

                *Automation was the most important driver*.
                More info on request.
                """)

    style = MarkdownStyle()
    style.h1.font.color = (21, 164, 58)
    style.h1.font.size = 14

    app = template.app
    app.screen_updating = False

    wb = create_report(template_path, report_path,
        perf_data=perf_data,
        logo=logo,
        perf=perf,
        fig=fig,
        summary=Markdown(mytext, style)
    )

    wb.sheets.active['A1'].select()
    app.screen_updating = True
Пример #2
0
def test_markdown_shape_unordered_list(app):
    shape = app.books["test book.xlsx"].sheets["shape"].shapes[0]
    shape.text = ""
    style = MarkdownStyle()
    style.unordered_list.bullet_character = "-"
    style.unordered_list.blank_lines_after = 1
    shape.text = Markdown(text1, style)

    assert shape.characters[29].text == "-"
    assert shape.characters[65:72].text == "Another"

    style.unordered_list.blank_lines_after = 2
    shape.text = ""
    shape.text = Markdown(text1, style)
    assert shape.characters[66:73].text == "Another"
Пример #3
0
def test_markdown_cell_unordered_list(app):
    cell = app.books["test book.xlsx"].sheets[0]["A1"]
    cell.clear()
    style = MarkdownStyle()
    style.unordered_list.bullet_character = "-"
    style.unordered_list.blank_lines_after = 1
    cell.value = Markdown(text1, style)

    assert cell.characters[29].text == "-"
    assert cell.characters[65:72].text == "Another"

    style.unordered_list.blank_lines_after = 2
    cell.clear()
    cell.value = Markdown(text1, style)
    assert cell.characters[66:73].text == "Another"
Пример #4
0
def test_markdown_cell_emphasis(app):
    cell = app.books["test book.xlsx"].sheets[0]["A1"]
    cell.clear()
    style = MarkdownStyle()
    style.emphasis.color = (255, 0, 0)
    style.emphasis.bold = False
    style.emphasis.size = 20
    style.emphasis.italic = True
    style.emphasis.name = "Arial"
    cell.value = Markdown(text1, style)

    assert cell.characters[21:27].font.color == (255, 0, 0)
    assert cell.characters[21:27].font.bold is False
    assert cell.characters[21:27].font.size == 20
    assert cell.characters[21:27].font.italic is True
    assert cell.characters[21:27].font.name == "Arial"
Пример #5
0
def test_markdown_shape_emphasis(app):
    shape = app.books["test book.xlsx"].sheets["shape"].shapes[0]
    shape.text = ""
    style = MarkdownStyle()
    style.emphasis.color = (255, 0, 0)
    style.emphasis.bold = False
    style.emphasis.size = 20
    style.emphasis.italic = True
    style.emphasis.name = "Arial"
    shape.text = Markdown(text1, style)

    assert shape.characters[21:27].font.color == (255, 0, 0)
    assert shape.characters[21:27].font.bold is False
    assert shape.characters[21:27].font.size == 20
    assert shape.characters[21:27].font.italic is True
    assert shape.characters[21:27].font.name == "Arial"
Пример #6
0
def test_markdown_cell_strong(app):
    cell = app.books["test book.xlsx"].sheets[0]['A1']
    cell.clear()
    style = MarkdownStyle()
    style.strong.color = (255, 0, 0)
    style.strong.bold = False
    style.strong.size = 20
    style.strong.italic = True
    style.strong.name = 'Arial'
    cell.value = Markdown(text1, style)

    assert cell.characters[12:16].font.color == (255, 0, 0)
    assert cell.characters[12:16].font.bold is False
    assert cell.characters[12:16].font.size == 20
    assert cell.characters[12:16].font.italic is True
    assert cell.characters[12:16].font.name == 'Arial'
Пример #7
0
def test_markdown_shape_strong(app):
    shape = app.books["test book.xlsx"].sheets['shape'].shapes[0]
    shape.text = ''
    style = MarkdownStyle()
    style.strong.color = (255, 0, 0)
    style.strong.bold = False
    style.strong.size = 20
    style.strong.italic = True
    style.strong.name = 'Arial'
    shape.text = Markdown(text1, style)

    assert shape.characters[12:16].font.color == (255, 0, 0)
    assert shape.characters[12:16].font.bold is False
    assert shape.characters[12:16].font.size == 20
    assert shape.characters[12:16].font.italic is True
    assert shape.characters[12:16].font.name == 'Arial'
Пример #8
0
def test_markdown_cell_h1(app):
    cell = app.books["test book.xlsx"].sheets[0]["A1"]
    cell.clear()
    style = MarkdownStyle()
    style.h1.blank_lines_after = 2
    style.h1.font.color = (255, 0, 0)
    style.h1.font.bold = False
    style.h1.font.size = 20
    style.h1.font.italic = True
    style.h1.font.name = "Arial"
    cell.value = Markdown(text1, style)

    for selection in [slice(0, 5), slice(68, 81)]:
        assert cell.characters[selection].font.color == (255, 0, 0)
        assert cell.characters[selection].font.bold is False
        assert cell.characters[selection].font.size == 20
        assert cell.characters[selection].font.italic is True
        assert cell.characters[selection].font.name == "Arial"
Пример #9
0
def test_markdown_shape_h1(app):
    shape = app.books["test book.xlsx"].sheets["shape"].shapes[0]
    shape.text = ""
    style = MarkdownStyle()
    style.h1.blank_lines_after = 2
    style.h1.font.color = (255, 0, 0)
    style.h1.font.bold = False
    style.h1.font.size = 20
    style.h1.font.italic = True
    style.h1.font.name = "Arial"
    shape.text = Markdown(text1, style)

    for selection in [slice(0, 5), slice(68, 81)]:
        assert shape.characters[selection].font.color == (255, 0, 0)
        assert shape.characters[selection].font.bold is False
        assert shape.characters[selection].font.size == 20
        assert shape.characters[selection].font.italic is True
        assert shape.characters[selection].font.name == "Arial"