In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to automate the mass distribution of payroll in Python". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how to automate the mass sending of wage slips by Python".
Process analysis
In fact, such a code, to sum up, there are only the following five steps: ① import related modules; ② read Excel forms; ③ login mailbox; ④ ready to send mail body; ⑤ send mail
1) Import related modules
From openpyxl import load_workbook # module for operating Excel import yagmail # module for storing email address and password import keyring # module for recording your email address and password from datetime import * # module for obtaining the current system time
2) read Excel table
# load the Excel file wb = load_workbook ("mass payroll .xlsx" Data_only=True) sheet = wb.activeprint (sheet)-for row in sheet: row_text = "" for cell in row: if cell.column = = "B": continue row_text + = f "{cell.value} "print (row_text)-print (" year: ", date.today () .year) print (" month: ", date.today () .month) print (f" {date.today () .year}-{date.today () .month} month ")
The results are as follows:
3) log in to the mailbox
Yagmail.register ("1127421544@qq.com", "flmyucvntuvbjbcb") pwd = keyring.get_password ("yagmail", "1127421544@qq.com") yag = yagmail.SMTP (user= "1127421544@qq.com", host= "smtp.qq.com", password=pwd)
It is important to note that the first line of code is used to store your email address and password. The second line of code uses keyring to record your email address and password. The third line of code logs directly into the mailbox.
4) prepare the text to be sent
Because we need to send an email with a form in the body, we need to know a little about the front end. Therefore, I will spend a chapter to explain it to you at the end of the day.
5) send email
Yag.send (f "{email}", f "data Analysis and Statistics Beauty Co., Ltd. {date.today (). Year}-{date.today (). Month} monthly salary", contents)
The above code has a total of three parameters: the first parameter is the recipient's mailbox; the second parameter is the title of the message; and the third parameter is the content sent.
Special notes on html code
Anyone who can send an email using Python knows that the body of the email can be written in html code. You may think you don't know anything, but don't worry, we don't need to learn too advanced front-end code, and people who have been crawlers can understand it.
1) write a simple front-end code by yourself
We can directly use Pycharm to create a new html file, which will show the initial front-end code, we simply add, we can get a table!
The final display in the browser is as follows:
The final display in the browser is as follows:
2) how to write front-end code in Python
As you can see from the image above, the entire front-end code is made up of a number of columns of tags, and the tags appear in pairs. Therefore, when you write the front-end code in Python, you only need to add the corresponding tag in the corresponding location.
For row in sheet: row_text = "" for cell in row: if cell.column = = "B": continue row_text + = f "{cell.value}" row_text + = "" print ("\ n") print (row_text)
The results are as follows:
At this point, I believe you have a deeper understanding of "Python how to achieve automatic mass payroll". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.