import openpyxl excel_path = 'data/excel/medium-voltage-KM 170126.xlsx' wb = openpyxl.load_workbook(excel_path) ws = wb.active # Technical data for 1x1200RM/35 # Indices based on Row 2 (Units) and Row 1 # Index 0: Part Number # Index 8: Querschnitt # Index 9: Rated voltage # Index 10: Test voltage # Index 23: LD mm # Index 24: ID mm # Index 25: DI mm # Index 26: MWD mm # Index 27: AD mm # Index 28: BR # Index 29: G kg # Index 30: RI Ohm # Index 31: Cap # Index 32: Inductance trefoil # Index 35: BK # Index 39: SBL 30 # Index 41: SBE 20 new_rows_data = [ { "voltage": "6/10", "test_v": 21, "ld": 41.5, "id": 3.4, "di": 48.5, "mwd": 2.1, "ad": 59, "br": 885, "g": 4800, "ri": 0.0247, "cap": 0.95, "ind": 0.24, "bk": 113, "sbl": 1300, "sbe": 933 }, { "voltage": "12/20", "test_v": 42, "ld": 41.5, "id": 5.5, "di": 52.3, "mwd": 2.1, "ad": 66, "br": 990, "g": 5200, "ri": 0.0247, "cap": 1.05, "ind": 0.23, "bk": 113, "sbl": 1200, "sbe": 900 }, { "voltage": "18/30", "test_v": 63, "ld": 41.5, "id": 8.0, "di": 57.5, "mwd": 2.4, "ad": 71, "br": 1065, "g": 5900, "ri": 0.0247, "cap": 1.15, "ind": 0.22, "bk": 113, "sbl": 1300, "sbe": 950 } ] # Find a template row for NA2XS(F)2Y template_row = None for row in ws.iter_rows(min_row=3, values_only=True): if row[0] == 'NA2XS(F)2Y' and row[9] == '6/10': template_row = list(row) break if not template_row: print("Error: Could not find template row for NA2XS(F)2Y") exit(1) # Function to update template with new values def create_row(template, data): new_row = template[:] new_row[8] = "1x1200/35" new_row[9] = data["voltage"] new_row[10] = data["test_v"] new_row[23] = data["ld"] new_row[24] = data["id"] new_row[25] = data["di"] new_row[26] = data["mwd"] new_row[27] = data["ad"] new_row[28] = data["br"] new_row[29] = data["g"] new_row[30] = data["ri"] new_row[31] = data["cap"] new_row[32] = data["ind"] new_row[35] = data["bk"] new_row[39] = data["sbl"] new_row[41] = data["sbe"] return new_row # Append new rows for data in new_rows_data: new_row_values = create_row(template_row, data) ws.append(new_row_values) print(f"Added row for {data['voltage']} kV") wb.save(excel_path) print("Excel file updated successfully.")