-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathchart_size.py
41 lines (31 loc) · 902 Bytes
/
chart_size.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
# chart_size.py
from openpyxl import Workbook
from openpyxl.chart import BarChart, Reference
def main(filename):
workbook = Workbook()
sheet = workbook.active
# Add data to spreadsheet
data_rows = [
["Book", "Kindle", "Paperback"],
[1, 9.99, 15.99],
[2, 9.99, 25.99],
[3, 9.99, 25.99],
[4, 4.99, 29.99],
[5, 14.99, 39.99],
]
for row in data_rows:
sheet.append(row)
# Create the bar chart
bar_chart = BarChart()
bar_chart.height = 20
bar_chart.width = 30
data = Reference(worksheet=sheet,
min_row=1,
max_row=10,
min_col=2,
max_col=3)
bar_chart.add_data(data, titles_from_data=True)
sheet.add_chart(bar_chart, "E2")
workbook.save(filename)
if __name__ == "__main__":
main("bar_chart_size.xlsx")