Есть код:
import openpyxl
from dataclasses import dataclass, fields
'Номеклатура PRP-4.xlsx'
@dataclass
class Element:
name: list
leg: list
itog: list
material: list
primechanie: list
vrezki: list
objLegVrez: list
gib: list
count: list
pages = ["PRP-qq000100", "PRP-qq000000", "PRP-qq000200"];
elements = [];
def createAllElements():
i = 0;
while i < len(pages):
createElement(pages[i])
i = i + 1
def getRow(letter, page):
wb = openpyxl.load_workbook('Номеклатура PRP-4.xlsx')
sheet = wb[page]
i = 15
u = 0
arr = []
while i < 1000:
i = i + 1
u = u + 1
if (sheet[letter + str(i)].value != None):
arr.append(sheet[letter + str(i)].value)
else:
break
return arr
def createElement(page):
el = Element(
name=getRow("I", page),
leg=getRow("J", page),
itog=getRow("K", page),
material=getRow("L", page),
primechanie=getRow("M", page),
vrezki=getRow("N", page),
objLegVrez=getRow("O", page),
gib=getRow("P", page),
count=getRow("Q", page))
elements.append(el)
print(el)
def writingFile(allElements):
wb = openpyxl.load_workbook('Номеклатура PRP-4.xlsx')
sheet = wb["All detals"]
writeRow(sheet, "I", allElements.name)
writeRow(sheet, "J", allElements.leg)
writeRow(sheet, "K", allElements.itog)
writeRow(sheet, "L", allElements.material)
writeRow(sheet, "M", allElements.primechanie)
writeRow(sheet, "N", allElements.vrezki)
writeRow(sheet, "O", allElements.objLegVrez)
writeRow(sheet, "P", allElements.gib)
writeRow(sheet, "Q", allElements.count)
wb.save('Номеклатура PRP-4.xlsx')
def combine(elements):
data = {field.name: sum([getattr(elem,field.name) for elem in elements],[]) for field in fields(elements[0])}
return Element(**data)
def writeRow(sheet, letter, arr):
print(arr)
i = 0
u = 0
while i < len(arr):
sheet[letter + str(i)].value = arr[i]
i = i + 1
u = u + 1
createAllElements()
allElements = combine(elements)
writingFile(allElements)
print(allElements)
Код стопорится только на записи в таблицу, allElements - верный.