Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize Excel Office Automation by Python

Shulou Source: shulou.com Published: 2022-06-01 23:51:27 10月03日 Update

In this issue, the editor will bring you about how to achieve Excel office automation in Python. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

The special processing here is mainly related to the date format data processing and commonly used aggregate data statistical processing, which can effectively achieve your common statistical requirements. The code is as follows:

# Statistics on the male-to-female ratio of employees def get_sex_percent (): sexlist= [] for rows in range (table.nrows-1): sexlist.append (table.cell (rows+1,2) .value) print (sexlist) print ("the male to female is:", round (sexlist.count ("male") / sexlist.count ("female", 2)) the output is: ['male', 'female', 'male' 'male', 'female', 'female', 'male', 'male', 'female', 'male' The male to female ratio is: 2.3 processing of time data type def get_date (): for rows in range (table.nrows): for cols in range (table.ncols): if (table.cell (rows,cols) .ctype = = 3): date=xlrd.xldate_as_datetime (table.cell (rows,cols). Value 0) print (date) # the last column of data statistical processing def get_statics (): sum=0 list1= [] for rows in range (table.nrows-1): sum+=int (table.cell (rows+1,table.ncols-1) .value) list1.append (int (table.cell (rows+1,table.ncols-1) .value) # print (table.cell (rows+1,8) .value) print ("the sum is:" Sum) # Sum print ("the avg is:", round (sum / table.ncols, 2)) # take the average print ("the max is:", sorted (list1) [- 1]) # take the maximum value print ("the min is:", sorted (list1) [0]) # take the minimum value if (len (list1)% 2): # determine whether the list length is odd or even Fetch the median print ("the median is:", (list1 [int (len (list1) / 2)] + list1 [int (len (list1) / 2x1)] / 2) else: print ("the median is:", list1 [int ((len (list1) + 1) / 2)])

If _ _ name__ = ='_ main__': get_date () get_statics ()

The code execution effect of the above two methods is as follows:

The above is the editor for you to share the Python how to achieve Excel office automation, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Processing data statistics men and women office automation code content common use data statistics analysis maximum minimum effective special professional two median small and medium rich in content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Xiaomi vpn Docker MySQL