import openpyxl excel_path = 'data/excel/medium-voltage-KM.xlsx' wb = openpyxl.load_workbook(excel_path) ws = wb.active # Technical data for 1x1200RM/35 new_rows_data = [ { "Rated voltage": "6/10", "Test voltage": 21, "Nominal insulation thickness": 3.4, "Diameter over insulation (approx.)": 48.5, "Minimum sheath thickness": 2.1, "Outer diameter (approx.)": 59, "Bending radius (min.)": 885, "Weight (approx.)": 4800, "Capacitance (approx.)": 0.95, "Inductance, trefoil (approx.)": 0.24, "Inductance in air, flat (approx.) 1": 0.40, "Inductance in ground, flat (approx.) 1": 0.42, }, { "Rated voltage": "12/20", "Test voltage": 42, "Nominal insulation thickness": 5.5, "Diameter over insulation (approx.)": 52.3, "Minimum sheath thickness": 2.1, "Outer diameter (approx.)": 66, "Bending radius (min.)": 990, "Weight (approx.)": 5200, "Capacitance (approx.)": 1.05, "Inductance, trefoil (approx.)": 0.23, "Inductance in air, flat (approx.) 1": 0.43, "Inductance in ground, flat (approx.) 1": 0.45, }, { "Rated voltage": "18/30", "Test voltage": 63, "Nominal insulation thickness": 8.0, "Diameter over insulation (approx.)": 57.5, "Minimum sheath thickness": 2.4, "Outer diameter (approx.)": 71, "Bending radius (min.)": 1065, "Weight (approx.)": 5900, "Capacitance (approx.)": 1.15, "Inductance, trefoil (approx.)": 0.22, "Inductance in air, flat (approx.) 1": 0.45, "Inductance in ground, flat (approx.) 1": 0.47, } ] # Find a template row for NA2XS(F)2Y template_row = None headers = [cell.value for cell in ws[1]] for row in ws.iter_rows(min_row=3, values_only=True): if row[0] == 'NA2XS(F)2Y': 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, updates, headers): new_row = template[:] # Change "Number of cores and cross-section" cs_idx = headers.index("Number of cores and cross-section") new_row[cs_idx] = "1x1200/35" # Apply specific updates for key, value in updates.items(): if key in headers: idx = headers.index(key) new_row[idx] = value return new_row # Append new rows for data in new_rows_data: new_row_values = create_row(template_row, data, headers) ws.append(new_row_values) print(f"Added row for {data['Rated voltage']} kV") wb.save(excel_path) print("Excel file updated successfully.")