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"
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"
def test_markdown_cell_defaults_value(app): cell = app.books["test book.xlsx"].sheets[0]["A1"] cell.clear() cell.value = Markdown(text1) assert ( cell.value == "Title\n\nText bold and italic\n\n• a first bullet\n• a second bullet\n\n" "Another title\n\nthis has a line break\nnew line" )
def test_markdown_shape_defaults_value(app): shape = app.books["test book.xlsx"].sheets["shape"].shapes[0] shape.text = "" shape.text = Markdown(text1) assert ( shape.text == "Title\n\nText bold and italic\n\n• a first bullet\n• a second bullet\n\n" "Another title\n\nthis has a line break\nnew line" )
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
def test_markdown_cell_defaults_formatting(app): cell = app.books["test book.xlsx"].sheets[0]["A1"] cell.clear() cell.value = Markdown(text1) assert cell.font.name == "Calibri" assert cell.font.size == 11 assert cell.characters[:5].font.bold is True assert cell.characters[7:11].font.bold is False assert cell.characters[7:11].font.italic is False assert cell.characters[21:27].font.italic is True assert cell.characters[65:78].font.bold is True
def test_markdown_shape_defaults_formatting(app): shape = app.books["test book.xlsx"].sheets["shape"].shapes[0] shape.text = "" shape.text = Markdown(text1) assert shape.font.name == "Calibri" assert shape.font.size == 11 assert shape.characters[:5].font.bold is True assert shape.characters[7:11].font.bold is False assert shape.characters[7:11].font.italic is False assert shape.characters[21:27].font.italic is True assert shape.characters[65:78].font.bold is True
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"
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"
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'
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'
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"
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"
fig = Figure(figsize=(4, 3)) ax = fig.add_subplot(111) ax.plot([1, 2, 3, 4, 5]) df1 = pd.DataFrame(index=['r0', 'r1'], columns=['c0', 'c1'], data=[[1., 1.], [1., 1.]]) data = dict(mystring='stringtest', myfloat=12.12, substring='substringtest', df1=df1, mydict={'df': df1}, pic=Image.open(os.path.abspath('xlwings.jpg')), fig=fig, markdown_cell=Markdown(text1), markdown_shape=Markdown(text1)) class TestCreateReport(unittest.TestCase): @classmethod def setUpClass(cls): cls.wb = create_report('template1.xlsx', 'output.xlsx', **data) @classmethod def tearDownClass(cls): xw.Book('output.xlsx').app.quit() def test_string(self): self.assertEqual(self.wb.sheets[0]['A1'].value, 'stringtest')