#What I have so far that doesn't work as I get the error: ValueError: not enough values to unpack (expected 2, got 1).
for cell in ws[fullname_column][1:]:
firstname, lastname = cell.value.split()
ws.cell(row=cell.row, column=firstname_column).value = firstname
ws.cell(row=cell.row, column=lastname_column).value = lastname
CodePudding user response:
Instead of
firstname, lastname = cell.value.split()
You should
- Split and check the length of the returned list.
- If length is 1 then probably you only have 1st name
- If length is 2 then u have both 1st and last name
CodePudding user response:
in openpyxl you can get values by rows, something like this:
sheet[f"A{index}"].value)
So if column A is name and B is a surname, you can get values for both individually.
Here index
is row number