I have an excel table with column names, no values, just like this:
table_name|column_a|column_b|column_c|column_d
empty row below
I have a list of values, like this [column_a, column_c]
I need a for loop that goes through the worksheet, finds a column name from the list and sets a cell value just below the column name, eg. NULL.
for row in worksheet.rows:
for cell in row:
if cell.value in col_names:
cell(offset(row=1, column=0)).value='NULL'
This is what I'm getting: NameError: name 'offset' is not defined
Edit: CharlieClark suggestion helped. Here's what I had to change
cell(offset(row=1, column=0)).value -> cell.offset(row=1, column=0).value
CharlieClark's suggestion helped. Here's what I had to change:
cell(offset(row=1, column=0)).value -> cell.offset(row=1, column=0).value
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.