-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsheetMerger.py
More file actions
26 lines (25 loc) · 1.02 KB
/
sheetMerger.py
File metadata and controls
26 lines (25 loc) · 1.02 KB
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
#! python3
# Read data from one spreadsheet and write it to parts of other spreadsheets.
import openpyxl
print('Opening both spreadsheets...')
exampleWb = openpyxl.load_workbook('example.xlsx')
landWb = openpyxl.load_workbook('lands.xlsx')
exampleSheet = exampleWb['Sheet1']
landSheet = landWb['Sheet1']
print('Getting values from lands.xlsx...')
for row in range(1, landSheet.max_row + 1):
landName = landSheet['A' + str(row)].value
landLenght = landSheet['B' + str(row)].value
landBreath = landSheet['C' + str(row)].value
print('Appending land.xlsx values to example.xlsx...')
for cells in exampleSheet['A8':'A10']:
for cell in cells:
cell.value = landName
for cells in exampleSheet['B8':'B10']:
for cell in cells:
cell.value = landLenght
for cells in exampleSheet['C8':'C10']:
for cell in cells:
cell.value = landBreath
print('Saving to a new file: newExample.xlsx in your directory...')
exampleWb.save('newExample.xlsx')