-
Notifications
You must be signed in to change notification settings - Fork 5
/
21_comments.py
61 lines (49 loc) · 1.83 KB
/
21_comments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
# vim: set fileencoding=utf-8
#
# (C) Copyright 2021 Pavel Tisnovsky
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Pavel Tisnovsky
#
#
# link to source:
# https://github.com/tisnik/most-popular-python-libs/blob/master/PySimpleGUI/21_comments.py
#
# link to source in literate programming format:
# https://tisnik.github.io/most-popular-python-libs/PySimpleGUI/21_comments.html
"""Tabulka s komentáři přirazenými k vybraným buňkám."""
import xlsxwriter
# vytvoření objektu reprezentujícího celý sešit
with xlsxwriter.Workbook("example21.xlsx") as workbook:
# vložení nového listu do sešitu
worksheet = workbook.add_worksheet()
# definice nového stylu
bold_style = workbook.add_format()
bold_style.set_bold()
bold_style.set_font_color("blue")
# definice dalšího nového stylu
red_style = workbook.add_format()
red_style.set_font_color("red")
# definice formátu čísel
numeric_format = workbook.add_format({"num_format": "0.0000"})
# nastavení šířky sloupců a stylu
worksheet.set_column("A:A", 8, red_style)
worksheet.set_column("B:B", 14, numeric_format)
worksheet.set_column("C:Z", 2)
# styl pro první řádek
worksheet.set_row(0, 20, bold_style)
# buňky s textem
worksheet.write_string("A1", "x")
worksheet.write_string("B1", "1/x")
# buňky s numerickými hodnotami
for x in range(1, 21):
worksheet.write_number(x, 0, x)
worksheet.write_number(x, 1, 1.0 / x)
worksheet.write_comment(x, 1, "Výsledek výrazu 1/{}".format(x))
# sešit bude uzavřen automaticky