hello Python Bits following the proposed exercise, if I had a list. of the same size as column c, but I would like to add my list example, my_list=['a','b','c','d','e','f','g','h', 'm'] in column d, as I introduce with the for loop method, if when I did it, it only copied the last element of the list, in this case m is copied in all rows from 2 to 9. and not like this all the elements in the list. greetings.
Is it possible to update the cells dynamically using iter_row ? I have a for loop that iterates between a min_row and max_row. The problem is that when I print (row[0]), it correctly prints the value of the first cell in each row between the selected min and max. But i want to now use the same for loop with iter_row to dynamically update the value of row[0] in each row between the selected min and max. Thats where my code is failing. Any help will be much appreciated.
You can re-assign value to same cell (ex. i.value = 'NEW_VALUE' ) within your loop and then add wb.save('BOOK.xlsx') as a last statement. If you don't add save command then changes will not be reflected in the excel sheet.
Yes. You need to get both worksheets (like wb1 and wb2), access cell in both sheets and assign values. You can add wb1 and wb2 under some kind of loop and update at the same time.
Why when I run these: for i in range(2,10): b_col = ws.cell(row=i,column=2).value c_value = b_col*2 ws.cell(row=i, column=3).value = c_value it shows me this kind of error: unsupported operand type(s) for *: 'NoneType' and 'int'
One of your cell is returning None value. If you try putting None*2 in python console, you will see same error. Try adding if statement to eliminate None before multiplication.
type error: unsupported operand types for * : 'None Type' and 'int' -----at line number 17 where we are doing the mathematical calculation solve this issue
One of the cell in B column is blank, so when loop comes to blank cell, it saves None as a b_cell value. If you try to multiply anything with None/NoneType, it throws this error. To avoid this add a if condition there if b_col != None: c_value = b_col*2 ws.cell(row=i, column=3).value = c_value
Love your videos - clear transitions and explanations. Look forward to other Python videos!
Glad you like them!
Super clear you saved my day fella ! Many thx
Excellent work friend. You've managed to provide a lot of detail in a handful of small very direct videos.
hello
Python Bits
following the proposed exercise, if I had a list. of the same size as column c, but I would like to add my list example, my_list=['a','b','c','d','e','f','g','h', 'm'] in column d, as I introduce with the for loop method, if when I did it, it only copied the last element of the list, in this case m is copied in all rows from 2 to 9. and not like this all the elements in the list. greetings.
Is it possible to update the cells dynamically using iter_row ? I have a for loop that iterates between a min_row and max_row. The problem is that when I print (row[0]), it correctly prints the value of the first cell in each row between the selected min and max. But i want to now use the same for loop with iter_row to dynamically update the value of row[0] in each row between the selected min and max. Thats where my code is failing. Any help will be much appreciated.
You can re-assign value to same cell (ex. i.value = 'NEW_VALUE' ) within your loop and then add wb.save('BOOK.xlsx') as a last statement. If you don't add save command then changes will not be reflected in the excel sheet.
Is it possible to make changes without closing excel file. Can we make excel file dynamic
Is it possible to add vallue in two sheets at the same time?
Yes. You need to get both worksheets (like wb1 and wb2), access cell in both sheets and assign values. You can add wb1 and wb2 under some kind of loop and update at the same time.
Thank you very much😍
Thank You sir
nice bro
Nice video. Thanks!
Glad you liked it!
i cannot save in the same file name,it asks me to change the name and it works, but i want in the same file name
Why when I run these:
for i in range(2,10):
b_col = ws.cell(row=i,column=2).value
c_value = b_col*2
ws.cell(row=i, column=3).value = c_value
it shows me this kind of error: unsupported operand type(s) for *: 'NoneType' and 'int'
One of your cell is returning None value. If you try putting None*2 in python console, you will see same error. Try adding if statement to eliminate None before multiplication.
how do you read and write a merged cell?
type error: unsupported operand types for * : 'None Type' and 'int' -----at line number 17 where we are doing the mathematical calculation
solve this issue
One of the cell in B column is blank, so when loop comes to blank cell, it saves None as a b_cell value. If you try to multiply anything with None/NoneType, it throws this error. To avoid this add a if condition there
if b_col != None:
c_value = b_col*2
ws.cell(row=i, column=3).value = c_value
I'm facing an attribute error cell is not in workbook
Make sure openpxl function/property name you're trying to use is correct. This will most likely happens due to typo error in method names.
ws.cell(row=i, column=6).value=f_col it's not same f_col=ws.cell(row=i, column=6).value
?? why
Mmmm.... Indian...
Im in deal !)