53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
|
import openpyxl
|
||
|
|
||
|
def excel_row_to_string(file_path):
|
||
|
# Öffne die Excel-Datei
|
||
|
workbook = openpyxl.load_workbook(file_path)
|
||
|
|
||
|
# Wähle das Arbeitsblatt aus
|
||
|
sheet = workbook['Sheet1']
|
||
|
|
||
|
# Erhalte die angegebene Zeile als Liste von Zellen
|
||
|
row_values = [cell.value for cell in sheet[2]]
|
||
|
|
||
|
# Ergebnisse werden ab Spalte 5 eingetragen
|
||
|
selected_columns = list(range(4, len(row_values)))
|
||
|
|
||
|
# Wähle nur die gewünschten Spalten aus
|
||
|
selected_values = [row_values[col] for col in selected_columns]
|
||
|
|
||
|
# Schließe die Excel-Datei
|
||
|
workbook.close()
|
||
|
|
||
|
# Konvertiere die Liste von Zellen in einen String
|
||
|
row_string = ', '.join(str(value) for value in selected_values)
|
||
|
|
||
|
return row_string
|
||
|
|
||
|
def write_string_to_excel(file_path, input_string):
|
||
|
# Öffne die Excel-Datei
|
||
|
workbook = openpyxl.load_workbook(file_path)
|
||
|
|
||
|
# Wähle das Arbeitsblatt aus
|
||
|
sheet = workbook['Sheet1']
|
||
|
|
||
|
# Teile den String nach jedem Komma auf
|
||
|
parts = input_string.split(',')
|
||
|
|
||
|
# Trage jeden Teil des Strings in eine neue Zeile ein
|
||
|
for i, part in enumerate(parts, 1):
|
||
|
sheet.cell(row=2 + i - 1, column=17, value=part.strip()) # strip entfernt mögliche Leerzeichen
|
||
|
|
||
|
# Speichere die Änderungen
|
||
|
workbook.save(file_path)
|
||
|
|
||
|
# Schließe die Excel-Datei
|
||
|
workbook.close()
|
||
|
|
||
|
# Funktionsaufrufe
|
||
|
|
||
|
input_string = excel_row_to_string('Testruns.xlsx')
|
||
|
|
||
|
write_string_to_excel('Testcase_excel_dataset.xlsx', input_string)
|
||
|
|