SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
from openpyxl import *
sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4
def col2num(col):
num = 0
for c in col:
if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
num = num * 26 + (ord(c.upper()) - (ord('A')-1))
return num
def make_sheets(sheet_path, input_end, output_end, non_temp_sheets):
wb = load_workbook(sheet_path)
numeric_input_end = col2num(input_end)
numeric_output_end = col2num(output_end)
template_sheet = wb["Template"]
multi_input_sheet = wb["Multi Input"]
# removing excess sheets from previous runs
for name in wb.sheetnames[non_temp_sheets:]:
wb.remove(wb[name])
rows = [_ for _ in multi_input_sheet.iter_rows()]
for row in rows[3:]:
row_id = str(row[2].value)
if row_id == "None": continue
# make a copy of the template & name the sheet with the id
iter_sheet = wb.copy_worksheet(template_sheet)
iter_sheet.title = row_id
print("Processing member ID: " + row_id)
# inputting
for input_cell in row[:numeric_input_end]:
iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row)
# outputting
for output_cell in row[numeric_input_end:numeric_output_end]:
output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value
print("Saving...")
wb.save(sheet_path)
wb.close()
print("Done.")
make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
Input Cells
Cell Description
Q14 Project Name
Q16 Item Name
U16 ID
C4 Lb_in
C5 Lb_out
C6 L_LTB
C7 Cb
C10 Type
C11 Rolled Profile
A26 h
A27 b
A28 tf
A29 tw
C14 Pu
C15 Mux
C16 Muy
C17 Vu
C20 fy
C21 fu
C22 E
Output Cells
Cell Description
U19 Compactness
U20 Compression
U21 Flexure
U22 Shear
U23 Interaction
K27 P Utilization
O24 Mx Utilization
G6 Section Area
1. Prepare Workbook with Template and Multi-input Sheets
2. Open Workbook → wb
3. Open Multi-input Sheet → multi_input_sheet
4. Open Template Sheet → template_sheet
5. Get input/output cell titles (row 2 in multi_input_sheet) → input_titles; output_titles
6. Foreach data_row in multi_input_sheet:
7. Create Copy of template_sheet → iter_sheet where iter_sheet.title equals data_row.id
8. Get input cells in row → input_cells
9. Get output cells in row → output_cells
10. Foreach input_cell in input_cells:
11. iter_sheet.cell(idx_of(input_title)).value equals "='Multi Input'!" + idx_of(input_cell)
12. Foreach output_cell in output_cells:
13. output_cell.value equals "=" + data_row.id + "'!" + output_title
14. Save wb
15. Close wb
from openpyxl import *
sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4
def col2num(col):
num = 0
for c in col:
if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
num = num * 26 + (ord(c.upper()) - (ord('A')-1))
return num
def make_sheets(sheet_path, input_end, output_end, non_temp_sheets):
wb = load_workbook(sheet_path)
numeric_input_end = col2num(input_end)
numeric_output_end = col2num(output_end)
template_sheet = wb["Template"]
multi_input_sheet = wb["Multi Input"]
# removing excess sheets from previous runs
for name in wb.sheetnames[non_temp_sheets:]:
wb.remove(wb[name])
rows = [_ for _ in multi_input_sheet.iter_rows()]
for row in rows[3:]:
row_id = str(row[2].value)
if row_id == "None": continue
# make a copy of the template & name the sheet with the id
iter_sheet = wb.copy_worksheet(template_sheet)
iter_sheet.title = row_id
print("Processing member ID: " + row_id)
# inputting
for input_cell in row[:numeric_input_end]:
iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row)
# outputting
for output_cell in row[numeric_input_end:numeric_output_end]:
output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value
print("Saving...")
wb.save(sheet_path)
wb.close()
print("Done.")
make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
from openpyxl import *
sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4
def col2num(col):
num = 0
for c in col:
if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
num = num * 26 + (ord(c.upper()) - (ord('A')-1))
return num
def make_sheets(sheet_path, input_end, output_end, non_temp_sheets):
wb = load_workbook(sheet_path)
numeric_input_end = col2num(input_end)
numeric_output_end = col2num(output_end)
template_sheet = wb["Template"]
multi_input_sheet = wb["Multi Input"]
# removing excess sheets from previous runs
for name in wb.sheetnames[non_temp_sheets:]:
wb.remove(wb[name])
rows = [_ for _ in multi_input_sheet.iter_rows()]
for row in rows[3:]:
row_id = str(row[2].value)
if row_id == "None": continue
# make a copy of the template & name the sheet with the id
iter_sheet = wb.copy_worksheet(template_sheet)
iter_sheet.title = row_id
print("Processing member ID: " + row_id)
# inputting
for input_cell in row[:numeric_input_end]:
iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row)
# outputting
for output_cell in row[numeric_input_end:numeric_output_end]:
output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value
print("Saving...")
wb.save(sheet_path)
wb.close()
print("Done.")
make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
from openpyxl import *
sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4
def col2num(col):
num = 0
for c in col:
if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
num = num * 26 + (ord(c.upper()) - (ord('A')-1))
return num
def make_sheets(sheet_path, input_end, output_end, non_temp_sheets):
wb = load_workbook(sheet_path)
numeric_input_end = col2num(input_end)
numeric_output_end = col2num(output_end)
template_sheet = wb["Template"]
multi_input_sheet = wb["Multi Input"]
# removing excess sheets from previous runs
for name in wb.sheetnames[non_temp_sheets:]:
wb.remove(wb[name])
rows = [_ for _ in multi_input_sheet.iter_rows()]
for row in rows[3:]:
row_id = str(row[2].value)
if row_id == "None": continue
# make a copy of the template & name the sheet with the id
iter_sheet = wb.copy_worksheet(template_sheet)
iter_sheet.title = row_id
print("Processing member ID: " + row_id)
# inputting
for input_cell in row[:numeric_input_end]:
iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row)
# outputting
for output_cell in row[numeric_input_end:numeric_output_end]:
output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value
print("Saving...")
wb.save(sheet_path)
wb.close()
print("Done.")
make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
from openpyxl import *
sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4
def col2num(col):
num = 0
for c in col:
if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
num = num * 26 + (ord(c.upper()) - (ord('A')-1))
return num
def make_sheets(sheet_path, input_end, output_end, non_temp_sheets):
wb = load_workbook(sheet_path)
numeric_input_end = col2num(input_end)
numeric_output_end = col2num(output_end)
template_sheet = wb["Template"]
multi_input_sheet = wb["Multi Input"]
# removing excess sheets from previous runs
for name in wb.sheetnames[non_temp_sheets:]:
wb.remove(wb[name])
rows = [_ for _ in multi_input_sheet.iter_rows()]
for row in rows[3:]:
row_id = str(row[2].value)
if row_id == "None": continue
# make a copy of the template & name the sheet with the id
iter_sheet = wb.copy_worksheet(template_sheet)
iter_sheet.title = row_id
print("Processing member ID: " + row_id)
# inputting
for input_cell in row[:numeric_input_end]:
iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row)
# outputting
for output_cell in row[numeric_input_end:numeric_output_end]:
output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value
print("Saving...")
wb.save(sheet_path)
wb.close()
print("Done.")
make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
from openpyxl import *
sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4
def col2num(col):
num = 0
for c in col:
if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
num = num * 26 + (ord(c.upper()) - (ord('A')-1))
return num
def make_sheets(sheet_path, input_end, output_end, non_temp_sheets):
wb = load_workbook(sheet_path)
numeric_input_end = col2num(input_end)
numeric_output_end = col2num(output_end)
template_sheet = wb["Template"]
multi_input_sheet = wb["Multi Input"]
# removing excess sheets from previous runs
for name in wb.sheetnames[non_temp_sheets:]:
wb.remove(wb[name])
rows = [_ for _ in multi_input_sheet.iter_rows()]
for row in rows[3:]:
row_id = str(row[2].value)
if row_id == "None": continue
# make a copy of the template & name the sheet with the id
iter_sheet = wb.copy_worksheet(template_sheet)
iter_sheet.title = row_id
print("Processing member ID: " + row_id)
# inputting
for input_cell in row[:numeric_input_end]:
iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row)
# outputting
for output_cell in row[numeric_input_end:numeric_output_end]:
output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value
print("Saving...")
wb.save(sheet_path)
wb.close()
print("Done.")
make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
from openpyxl import *
sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4
def col2num(col):
num = 0
for c in col:
if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
num = num * 26 + (ord(c.upper()) - (ord('A')-1))
return num
def make_sheets(sheet_path, input_end, output_end, non_temp_sheets):
wb = load_workbook(sheet_path)
numeric_input_end = col2num(input_end)
numeric_output_end = col2num(output_end)
template_sheet = wb["Template"]
multi_input_sheet = wb["Multi Input"]
# removing excess sheets from previous runs
for name in wb.sheetnames[non_temp_sheets:]:
wb.remove(wb[name])
rows = [_ for _ in multi_input_sheet.iter_rows()]
for row in rows[3:]:
row_id = str(row[2].value)
if row_id == "None": continue
# make a copy of the template & name the sheet with the id
iter_sheet = wb.copy_worksheet(template_sheet)
iter_sheet.title = row_id
print("Processing member ID: " + row_id)
# inputting
for input_cell in row[:numeric_input_end]:
iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row)
# outputting
for output_cell in row[numeric_input_end:numeric_output_end]:
output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value
print("Saving...")
wb.save(sheet_path)
wb.close()
print("Done.")
make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
from openpyxl import *
sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4
def col2num(col):
num = 0
for c in col:
if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
num = num * 26 + (ord(c.upper()) - (ord('A')-1))
return num
def make_sheets(sheet_path, input_end, output_end, non_temp_sheets):
wb = load_workbook(sheet_path)
numeric_input_end = col2num(input_end)
numeric_output_end = col2num(output_end)
template_sheet = wb["Template"]
multi_input_sheet = wb["Multi Input"]
# removing excess sheets from previous runs
for name in wb.sheetnames[non_temp_sheets:]:
wb.remove(wb[name])
rows = [_ for _ in multi_input_sheet.iter_rows()]
for row in rows[3:]:
row_id = str(row[2].value)
if row_id == "None": continue
# make a copy of the template & name the sheet with the id
iter_sheet = wb.copy_worksheet(template_sheet)
iter_sheet.title = row_id
print("Processing member ID: " + row_id)
# inputting
for input_cell in row[:numeric_input_end]:
iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row)
# outputting
for output_cell in row[numeric_input_end:numeric_output_end]:
output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value
print("Saving...")
wb.save(sheet_path)
wb.close()
print("Done.")
make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
from openpyxl import *
sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4
def col2num(col):
num = 0
for c in col:
if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
num = num * 26 + (ord(c.upper()) - (ord('A')-1))
return num
def make_sheets(sheet_path, input_end, output_end, non_temp_sheets):
wb = load_workbook(sheet_path)
numeric_input_end = col2num(input_end)
numeric_output_end = col2num(output_end)
template_sheet = wb["Template"]
multi_input_sheet = wb["Multi Input"]
# removing excess sheets from previous runs
for name in wb.sheetnames[non_temp_sheets:]:
wb.remove(wb[name])
rows = [_ for _ in multi_input_sheet.iter_rows()]
for row in rows[3:]:
row_id = str(row[2].value)
if row_id == "None": continue
# make a copy of the template & name the sheet with the id
iter_sheet = wb.copy_worksheet(template_sheet)
iter_sheet.title = row_id
print("Processing member ID: " + row_id)
# inputting
for input_cell in row[:numeric_input_end]:
iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row)
# outputting
for output_cell in row[numeric_input_end:numeric_output_end]:
output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value
print("Saving...")
wb.save(sheet_path)
wb.close()
print("Done.")
make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
from openpyxl import *
sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4
def col2num(col):
num = 0
for c in col:
if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
num = num * 26 + (ord(c.upper()) - (ord('A')-1))
return num
def make_sheets(sheet_path, input_end, output_end, non_temp_sheets):
wb = load_workbook(sheet_path)
numeric_input_end = col2num(input_end)
numeric_output_end = col2num(output_end)
template_sheet = wb["Template"]
multi_input_sheet = wb["Multi Input"]
# removing excess sheets from previous runs
for name in wb.sheetnames[non_temp_sheets:]:
wb.remove(wb[name])
rows = [_ for _ in multi_input_sheet.iter_rows()]
for row in rows[3:]:
row_id = str(row[2].value)
if row_id == "None": continue
# make a copy of the template & name the sheet with the id
iter_sheet = wb.copy_worksheet(template_sheet)
iter_sheet.title = row_id
print("Processing member ID: " + row_id)
# inputting
for input_cell in row[:numeric_input_end]:
iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row)
# outputting
for output_cell in row[numeric_input_end:numeric_output_end]:
output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value
print("Saving...")
wb.save(sheet_path)
wb.close()
print("Done.")
make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
from openpyxl import *
sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4
def col2num(col):
num = 0
for c in col:
if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
num = num * 26 + (ord(c.upper()) - (ord('A')-1))
return num
def make_sheets(sheet_path, input_end, output_end, non_temp_sheets):
wb = load_workbook(sheet_path)
numeric_input_end = col2num(input_end)
numeric_output_end = col2num(output_end)
template_sheet = wb["Template"]
multi_input_sheet = wb["Multi Input"]
# removing excess sheets from previous runs
for name in wb.sheetnames[non_temp_sheets:]:
wb.remove(wb[name])
rows = [_ for _ in multi_input_sheet.iter_rows()]
for row in rows[3:]:
row_id = str(row[2].value)
if row_id == "None": continue
# make a copy of the template & name the sheet with the id
iter_sheet = wb.copy_worksheet(template_sheet)
iter_sheet.title = row_id
print("Processing member ID: " + row_id)
# inputting
for input_cell in row[:numeric_input_end]:
iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row)
# outputting
for output_cell in row[numeric_input_end:numeric_output_end]:
output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value
print("Saving...")
wb.save(sheet_path)
wb.close()
print("Done.")
make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
from openpyxl import *
sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4
def col2num(col):
num = 0
for c in col:
if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
num = num * 26 + (ord(c.upper()) - (ord('A')-1))
return num
def make_sheets(sheet_path, input_end, output_end, non_temp_sheets):
wb = load_workbook(sheet_path)
numeric_input_end = col2num(input_end)
numeric_output_end = col2num(output_end)
template_sheet = wb["Template"]
multi_input_sheet = wb["Multi Input"]
# removing excess sheets from previous runs
for name in wb.sheetnames[non_temp_sheets:]:
wb.remove(wb[name])
rows = [_ for _ in multi_input_sheet.iter_rows()]
for row in rows[3:]:
row_id = str(row[2].value)
if row_id == "None": continue
# make a copy of the template & name the sheet with the id
iter_sheet = wb.copy_worksheet(template_sheet)
iter_sheet.title = row_id
print("Processing member ID: " + row_id)
# inputting
for input_cell in row[:numeric_input_end]:
iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row)
# outputting
for output_cell in row[numeric_input_end:numeric_output_end]:
output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value
print("Saving...")
wb.save(sheet_path)
wb.close()
print("Done.")
make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
Automate ANY Excel Design Sheet Using python’s openpyxl.pdf
Automate ANY Excel Design Sheet Using python’s openpyxl.pdf
Automate ANY Excel Design Sheet Using python’s openpyxl.pdf
Automate ANY Excel Design Sheet Using python’s openpyxl.pdf
Automate ANY Excel Design Sheet Using python’s openpyxl.pdf
Automate ANY Excel Design Sheet Using python’s openpyxl.pdf
Automate ANY Excel Design Sheet Using python’s openpyxl.pdf

Más contenido relacionado

Similar a Automate ANY Excel Design Sheet Using python’s openpyxl.pdf

import os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docximport os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
Blake0FxCampbelld
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
amitbagga0808
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
rushabhshah600
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
Adamq0DJonese
 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
afgt2012
 

Similar a Automate ANY Excel Design Sheet Using python’s openpyxl.pdf (20)

Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
calculator_new (1).pdf
calculator_new (1).pdfcalculator_new (1).pdf
calculator_new (1).pdf
 
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docximport os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
 
p.pdf
p.pdfp.pdf
p.pdf
 
C program
C programC program
C program
 
unit-2-dsa.pptx
unit-2-dsa.pptxunit-2-dsa.pptx
unit-2-dsa.pptx
 
Swift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdfSwift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdf
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
Bcsl 033 solve assignment
Bcsl 033 solve assignmentBcsl 033 solve assignment
Bcsl 033 solve assignment
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILECOMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
 
Scala Functional Patterns
Scala Functional PatternsScala Functional Patterns
Scala Functional Patterns
 
Nesting of for loops using C++
Nesting of for loops using C++Nesting of for loops using C++
Nesting of for loops using C++
 
Python Lecture 6
Python Lecture 6Python Lecture 6
Python Lecture 6
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
 
Python From Scratch (1).pdf
Python From Scratch  (1).pdfPython From Scratch  (1).pdf
Python From Scratch (1).pdf
 

Último

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

Automate ANY Excel Design Sheet Using python’s openpyxl.pdf

  • 1.
  • 2. from openpyxl import * sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4 def col2num(col): num = 0 for c in col: if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": num = num * 26 + (ord(c.upper()) - (ord('A')-1)) return num def make_sheets(sheet_path, input_end, output_end, non_temp_sheets): wb = load_workbook(sheet_path) numeric_input_end = col2num(input_end) numeric_output_end = col2num(output_end) template_sheet = wb["Template"] multi_input_sheet = wb["Multi Input"] # removing excess sheets from previous runs for name in wb.sheetnames[non_temp_sheets:]: wb.remove(wb[name]) rows = [_ for _ in multi_input_sheet.iter_rows()] for row in rows[3:]: row_id = str(row[2].value) if row_id == "None": continue # make a copy of the template & name the sheet with the id iter_sheet = wb.copy_worksheet(template_sheet) iter_sheet.title = row_id print("Processing member ID: " + row_id) # inputting for input_cell in row[:numeric_input_end]: iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row) # outputting for output_cell in row[numeric_input_end:numeric_output_end]: output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value print("Saving...") wb.save(sheet_path) wb.close() print("Done.") make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
  • 3.
  • 4.
  • 5.
  • 6. Input Cells Cell Description Q14 Project Name Q16 Item Name U16 ID C4 Lb_in C5 Lb_out C6 L_LTB C7 Cb C10 Type C11 Rolled Profile A26 h A27 b A28 tf A29 tw C14 Pu C15 Mux C16 Muy C17 Vu C20 fy C21 fu C22 E Output Cells Cell Description U19 Compactness U20 Compression U21 Flexure U22 Shear U23 Interaction K27 P Utilization O24 Mx Utilization G6 Section Area
  • 7.
  • 8.
  • 9. 1. Prepare Workbook with Template and Multi-input Sheets 2. Open Workbook → wb 3. Open Multi-input Sheet → multi_input_sheet 4. Open Template Sheet → template_sheet 5. Get input/output cell titles (row 2 in multi_input_sheet) → input_titles; output_titles 6. Foreach data_row in multi_input_sheet: 7. Create Copy of template_sheet → iter_sheet where iter_sheet.title equals data_row.id 8. Get input cells in row → input_cells 9. Get output cells in row → output_cells 10. Foreach input_cell in input_cells: 11. iter_sheet.cell(idx_of(input_title)).value equals "='Multi Input'!" + idx_of(input_cell) 12. Foreach output_cell in output_cells: 13. output_cell.value equals "=" + data_row.id + "'!" + output_title 14. Save wb 15. Close wb
  • 10. from openpyxl import * sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4 def col2num(col): num = 0 for c in col: if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": num = num * 26 + (ord(c.upper()) - (ord('A')-1)) return num def make_sheets(sheet_path, input_end, output_end, non_temp_sheets): wb = load_workbook(sheet_path) numeric_input_end = col2num(input_end) numeric_output_end = col2num(output_end) template_sheet = wb["Template"] multi_input_sheet = wb["Multi Input"] # removing excess sheets from previous runs for name in wb.sheetnames[non_temp_sheets:]: wb.remove(wb[name]) rows = [_ for _ in multi_input_sheet.iter_rows()] for row in rows[3:]: row_id = str(row[2].value) if row_id == "None": continue # make a copy of the template & name the sheet with the id iter_sheet = wb.copy_worksheet(template_sheet) iter_sheet.title = row_id print("Processing member ID: " + row_id) # inputting for input_cell in row[:numeric_input_end]: iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row) # outputting for output_cell in row[numeric_input_end:numeric_output_end]: output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value print("Saving...") wb.save(sheet_path) wb.close() print("Done.") make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
  • 11. from openpyxl import * sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4 def col2num(col): num = 0 for c in col: if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": num = num * 26 + (ord(c.upper()) - (ord('A')-1)) return num def make_sheets(sheet_path, input_end, output_end, non_temp_sheets): wb = load_workbook(sheet_path) numeric_input_end = col2num(input_end) numeric_output_end = col2num(output_end) template_sheet = wb["Template"] multi_input_sheet = wb["Multi Input"] # removing excess sheets from previous runs for name in wb.sheetnames[non_temp_sheets:]: wb.remove(wb[name]) rows = [_ for _ in multi_input_sheet.iter_rows()] for row in rows[3:]: row_id = str(row[2].value) if row_id == "None": continue # make a copy of the template & name the sheet with the id iter_sheet = wb.copy_worksheet(template_sheet) iter_sheet.title = row_id print("Processing member ID: " + row_id) # inputting for input_cell in row[:numeric_input_end]: iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row) # outputting for output_cell in row[numeric_input_end:numeric_output_end]: output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value print("Saving...") wb.save(sheet_path) wb.close() print("Done.") make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
  • 12. from openpyxl import * sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4 def col2num(col): num = 0 for c in col: if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": num = num * 26 + (ord(c.upper()) - (ord('A')-1)) return num def make_sheets(sheet_path, input_end, output_end, non_temp_sheets): wb = load_workbook(sheet_path) numeric_input_end = col2num(input_end) numeric_output_end = col2num(output_end) template_sheet = wb["Template"] multi_input_sheet = wb["Multi Input"] # removing excess sheets from previous runs for name in wb.sheetnames[non_temp_sheets:]: wb.remove(wb[name]) rows = [_ for _ in multi_input_sheet.iter_rows()] for row in rows[3:]: row_id = str(row[2].value) if row_id == "None": continue # make a copy of the template & name the sheet with the id iter_sheet = wb.copy_worksheet(template_sheet) iter_sheet.title = row_id print("Processing member ID: " + row_id) # inputting for input_cell in row[:numeric_input_end]: iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row) # outputting for output_cell in row[numeric_input_end:numeric_output_end]: output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value print("Saving...") wb.save(sheet_path) wb.close() print("Done.") make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
  • 13. from openpyxl import * sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4 def col2num(col): num = 0 for c in col: if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": num = num * 26 + (ord(c.upper()) - (ord('A')-1)) return num def make_sheets(sheet_path, input_end, output_end, non_temp_sheets): wb = load_workbook(sheet_path) numeric_input_end = col2num(input_end) numeric_output_end = col2num(output_end) template_sheet = wb["Template"] multi_input_sheet = wb["Multi Input"] # removing excess sheets from previous runs for name in wb.sheetnames[non_temp_sheets:]: wb.remove(wb[name]) rows = [_ for _ in multi_input_sheet.iter_rows()] for row in rows[3:]: row_id = str(row[2].value) if row_id == "None": continue # make a copy of the template & name the sheet with the id iter_sheet = wb.copy_worksheet(template_sheet) iter_sheet.title = row_id print("Processing member ID: " + row_id) # inputting for input_cell in row[:numeric_input_end]: iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row) # outputting for output_cell in row[numeric_input_end:numeric_output_end]: output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value print("Saving...") wb.save(sheet_path) wb.close() print("Done.") make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
  • 14. from openpyxl import * sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4 def col2num(col): num = 0 for c in col: if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": num = num * 26 + (ord(c.upper()) - (ord('A')-1)) return num def make_sheets(sheet_path, input_end, output_end, non_temp_sheets): wb = load_workbook(sheet_path) numeric_input_end = col2num(input_end) numeric_output_end = col2num(output_end) template_sheet = wb["Template"] multi_input_sheet = wb["Multi Input"] # removing excess sheets from previous runs for name in wb.sheetnames[non_temp_sheets:]: wb.remove(wb[name]) rows = [_ for _ in multi_input_sheet.iter_rows()] for row in rows[3:]: row_id = str(row[2].value) if row_id == "None": continue # make a copy of the template & name the sheet with the id iter_sheet = wb.copy_worksheet(template_sheet) iter_sheet.title = row_id print("Processing member ID: " + row_id) # inputting for input_cell in row[:numeric_input_end]: iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row) # outputting for output_cell in row[numeric_input_end:numeric_output_end]: output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value print("Saving...") wb.save(sheet_path) wb.close() print("Done.") make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
  • 15. from openpyxl import * sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4 def col2num(col): num = 0 for c in col: if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": num = num * 26 + (ord(c.upper()) - (ord('A')-1)) return num def make_sheets(sheet_path, input_end, output_end, non_temp_sheets): wb = load_workbook(sheet_path) numeric_input_end = col2num(input_end) numeric_output_end = col2num(output_end) template_sheet = wb["Template"] multi_input_sheet = wb["Multi Input"] # removing excess sheets from previous runs for name in wb.sheetnames[non_temp_sheets:]: wb.remove(wb[name]) rows = [_ for _ in multi_input_sheet.iter_rows()] for row in rows[3:]: row_id = str(row[2].value) if row_id == "None": continue # make a copy of the template & name the sheet with the id iter_sheet = wb.copy_worksheet(template_sheet) iter_sheet.title = row_id print("Processing member ID: " + row_id) # inputting for input_cell in row[:numeric_input_end]: iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row) # outputting for output_cell in row[numeric_input_end:numeric_output_end]: output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value print("Saving...") wb.save(sheet_path) wb.close() print("Done.") make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
  • 16. from openpyxl import * sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4 def col2num(col): num = 0 for c in col: if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": num = num * 26 + (ord(c.upper()) - (ord('A')-1)) return num def make_sheets(sheet_path, input_end, output_end, non_temp_sheets): wb = load_workbook(sheet_path) numeric_input_end = col2num(input_end) numeric_output_end = col2num(output_end) template_sheet = wb["Template"] multi_input_sheet = wb["Multi Input"] # removing excess sheets from previous runs for name in wb.sheetnames[non_temp_sheets:]: wb.remove(wb[name]) rows = [_ for _ in multi_input_sheet.iter_rows()] for row in rows[3:]: row_id = str(row[2].value) if row_id == "None": continue # make a copy of the template & name the sheet with the id iter_sheet = wb.copy_worksheet(template_sheet) iter_sheet.title = row_id print("Processing member ID: " + row_id) # inputting for input_cell in row[:numeric_input_end]: iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row) # outputting for output_cell in row[numeric_input_end:numeric_output_end]: output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value print("Saving...") wb.save(sheet_path) wb.close() print("Done.") make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
  • 17. from openpyxl import * sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4 def col2num(col): num = 0 for c in col: if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": num = num * 26 + (ord(c.upper()) - (ord('A')-1)) return num def make_sheets(sheet_path, input_end, output_end, non_temp_sheets): wb = load_workbook(sheet_path) numeric_input_end = col2num(input_end) numeric_output_end = col2num(output_end) template_sheet = wb["Template"] multi_input_sheet = wb["Multi Input"] # removing excess sheets from previous runs for name in wb.sheetnames[non_temp_sheets:]: wb.remove(wb[name]) rows = [_ for _ in multi_input_sheet.iter_rows()] for row in rows[3:]: row_id = str(row[2].value) if row_id == "None": continue # make a copy of the template & name the sheet with the id iter_sheet = wb.copy_worksheet(template_sheet) iter_sheet.title = row_id print("Processing member ID: " + row_id) # inputting for input_cell in row[:numeric_input_end]: iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row) # outputting for output_cell in row[numeric_input_end:numeric_output_end]: output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value print("Saving...") wb.save(sheet_path) wb.close() print("Done.") make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
  • 18. from openpyxl import * sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4 def col2num(col): num = 0 for c in col: if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": num = num * 26 + (ord(c.upper()) - (ord('A')-1)) return num def make_sheets(sheet_path, input_end, output_end, non_temp_sheets): wb = load_workbook(sheet_path) numeric_input_end = col2num(input_end) numeric_output_end = col2num(output_end) template_sheet = wb["Template"] multi_input_sheet = wb["Multi Input"] # removing excess sheets from previous runs for name in wb.sheetnames[non_temp_sheets:]: wb.remove(wb[name]) rows = [_ for _ in multi_input_sheet.iter_rows()] for row in rows[3:]: row_id = str(row[2].value) if row_id == "None": continue # make a copy of the template & name the sheet with the id iter_sheet = wb.copy_worksheet(template_sheet) iter_sheet.title = row_id print("Processing member ID: " + row_id) # inputting for input_cell in row[:numeric_input_end]: iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row) # outputting for output_cell in row[numeric_input_end:numeric_output_end]: output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value print("Saving...") wb.save(sheet_path) wb.close() print("Done.") make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
  • 19. from openpyxl import * sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4 def col2num(col): num = 0 for c in col: if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": num = num * 26 + (ord(c.upper()) - (ord('A')-1)) return num def make_sheets(sheet_path, input_end, output_end, non_temp_sheets): wb = load_workbook(sheet_path) numeric_input_end = col2num(input_end) numeric_output_end = col2num(output_end) template_sheet = wb["Template"] multi_input_sheet = wb["Multi Input"] # removing excess sheets from previous runs for name in wb.sheetnames[non_temp_sheets:]: wb.remove(wb[name]) rows = [_ for _ in multi_input_sheet.iter_rows()] for row in rows[3:]: row_id = str(row[2].value) if row_id == "None": continue # make a copy of the template & name the sheet with the id iter_sheet = wb.copy_worksheet(template_sheet) iter_sheet.title = row_id print("Processing member ID: " + row_id) # inputting for input_cell in row[:numeric_input_end]: iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row) # outputting for output_cell in row[numeric_input_end:numeric_output_end]: output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value print("Saving...") wb.save(sheet_path) wb.close() print("Done.") make_sheets(sheet_path, input_end, output_end, non_temp_sheets)
  • 20. from openpyxl import * sheet_path, input_end, output_end, non_temp_sheets = file.xlsx", 'U', 'AB', 4 def col2num(col): num = 0 for c in col: if c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": num = num * 26 + (ord(c.upper()) - (ord('A')-1)) return num def make_sheets(sheet_path, input_end, output_end, non_temp_sheets): wb = load_workbook(sheet_path) numeric_input_end = col2num(input_end) numeric_output_end = col2num(output_end) template_sheet = wb["Template"] multi_input_sheet = wb["Multi Input"] # removing excess sheets from previous runs for name in wb.sheetnames[non_temp_sheets:]: wb.remove(wb[name]) rows = [_ for _ in multi_input_sheet.iter_rows()] for row in rows[3:]: row_id = str(row[2].value) if row_id == "None": continue # make a copy of the template & name the sheet with the id iter_sheet = wb.copy_worksheet(template_sheet) iter_sheet.title = row_id print("Processing member ID: " + row_id) # inputting for input_cell in row[:numeric_input_end]: iter_sheet[rows[1][input_cell.column - 1].value] = "='Multi Input'!" + utils.cell.get_column_letter(input_cell.column) + str(input_cell.row) # outputting for output_cell in row[numeric_input_end:numeric_output_end]: output_cell.value = "='" + iter_sheet.title + "'!" + rows[1][output_cell.column - 1].value print("Saving...") wb.save(sheet_path) wb.close() print("Done.") make_sheets(sheet_path, input_end, output_end, non_temp_sheets)