Skip to content

Commit d062e0b

Browse files
committed
add example for appendix c
1 parent cb8e582 commit d062e0b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

appendix_c_formulas/summing.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# summing.py
2+
3+
from openpyxl import Workbook
4+
5+
6+
def main(filename):
7+
workbook = Workbook()
8+
sheet = workbook.active
9+
10+
# Add data to spreadsheet
11+
data_rows = [
12+
["Book", "Kindle", "Paperback"],
13+
[1, 9.99, 15.99],
14+
[2, 9.99, 25.99],
15+
[3, 9.99, 25.99],
16+
[4, 4.99, 29.99],
17+
[5, 14.99, 39.99],
18+
]
19+
20+
for row in data_rows:
21+
sheet.append(row)
22+
23+
# Sum up columns
24+
sheet["A7"] = "Totals"
25+
sheet["B7"] = "=SUM(B2:B6)"
26+
sheet["C7"] = "=SUM(C2:C6)"
27+
workbook.save(filename)
28+
29+
30+
if __name__ == "__main__":
31+
main("summing.xlsx")

0 commit comments

Comments
 (0)