Forums

How do I check values in Excel file ?

Hello Everyone,

I am new in this forum and also new in python, just getting started with it and I was trying to do some task with python. I have an excel file that I want to automatically check if it meets the criteria that I want to set.

For example, I want that the python script to check if the first column has values only text then the second column has only double values and the third column has value integer, but, avoid the first row (since its title) and if so then it gives a message that is fine and if not then give a message where the error appears.

Thank you for your time and help.

You can use a library like openpyxl to read the file. Their tutorial covers how to do that, then you can use a bunch of if statements to perform the checks that you need.

Thank you for your reply, I knew about openpyxl and data manipulation in excel but I do not know how to set criteria to check data for validation.

Thank you

That would just be an if statement where you compare the content of the cell with the thing that you want to check. For example

if content_of_cell.contains("THIS"):
    print("cell contains THIS")

will check that the content of the cell (stored in the variable content_of_cell) has the string 'THIS' in it and print out if it does.

Thank you for your reply, it does make sense to use only if-else statement since i do not have to modify anything in excel file. Is there a limit on how much I can use of these statementes ?

No, there is not limit, though each one will take time, so adding more will add to the runtime of your code.

Thank you sir for your reply and help, Do you have any examples or link where I can see how it is done more efficiency ? and is there a button or a function in this site where I can set as Solved ? or to give you points ?

I don't think there are any specific tutorials on how to do that, no, but if you try it out you'll probably work out how to do it pretty quickly.

We don't have a "solved" button or a way to give people points on this site like Stack Overflow has, though perhaps we should!