Python uses pyexcel to verify and verify the data of spreadsheet files, such as data type, range, validity, etc

Environmental construction and preparation work: In order to use pyexcel to verify and verify the data of spreadsheet files, we need to make the following preparations: 1. Install Python: Ensure that Python is already installed on the computer. 2. Install pyExcel: You can use the pip tool to execute the following commands on the command line to install pyExcel: $ pip install pyexcel pyexcel-xlsx Dependent class libraries: 1. pyexcel: used to read and write spreadsheet files. 2. pyexcel xlsx: Used to process Excel file formats. After completing the above preparation work, we can proceed with the implementation of the following examples. The complete Python code is as follows: python import pyexcel def validate_data(data): error_msgs = [] for row in data: for value in row: if not isinstance(value, int): error_msgs.append(f"Invalid data type: {value}") if not 1 <= value <= 100: error_msgs.append(f"Data out of range: {value}") if not is_valid(value): error_msgs.append(f"Invalid data: {value}") return error_msgs def is_valid(value): #Customized legitimacy verification function #Returning True indicates legality, returning False indicates illegality return value % 2 == 0 def main(): #Read Excel file data = pyexcel.get_array(file_name='example.xlsx') #Data validation and validation error_msgs = validate_data(data) #Print verification error information if error_msgs: for msg in error_msgs: print(msg) else: print("Data is valid") if __name__ == "__main__": main() Sample explanation: The above code mainly includes the following parts: 1. 'validate'_ The 'data' function is used to verify and validate the incoming data. I did the following simple checksum verification in the sample: -Traverse each value in the data to determine if it is of integer type. If not, add error information to 'error'_ Msgs ` in the list. -Determine if the value is within the valid range (1 to 100), and if it is not within the range, add the error message to 'error'_ Msgs ` in the list. -Calling Custom Legitimacy Verification Function ` is_ Valid 'performs more complex verification, and if it does not comply with the rules, error information will be added to' error '_ Msgs ` in the list. -Return a list of validation error messages ` error_ Msgs `. 2. ` is_ The 'valid' function is used to customize validity validation rules. In this example, I only defined a simple rule that is only considered legal when the value is even. You can define more complex rules based on your own needs. 3. 'main' function: Main function used to read Excel files and call 'validate'_ The 'data' function performs data validation and validation. If there is a verification error message, print it out; otherwise, print "Data is valid". Summary: It is very convenient to use pyexcel to verify the data of spreadsheet files. Through the installation and introduction of class libraries in the preparation work, we can use pyExcel to read Excel files and verify and verify the data in them. The code in the example provides a simple example that you can expand and modify according to your own needs.