In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article Xiaobian for you to introduce in detail "python how to achieve automation office mail merge function", the content is detailed, the steps are clear, the details are handled properly, I hope that this "python how to achieve automation office mail merge function" article can help you solve doubts, following the editor's ideas slowly in-depth, together to learn new knowledge.
As shown in the following code, we can create csv files with name, mail, and date, and implement mail merge functions.
Import pandas as pdimport numpy as npimport randomimport csvfrom mailmerge import MailMerge# generated name def create_fname_data (): word_select = [] for i in range (97 Word_select.append (chr (I)) print (word_select) name_select = [] for i in range (6): name = "" for i in range (5): name+= random.choice (word_select) name+= "" for i in range (5): name+= random.choice (word_select) Name_select.append (name.title ()) print (name_select) return name_select# generate mailbox def create_mail (): word_select= [STR (I) for i in range (9)] all_number_select= [] for i in range (6): number_select= "" for i in range (10): number_select+=random.choice (word_select) endwith= ["@ 163.com" "@ qq.com", "@ icloud.com"] number_select+=random.choice (endwith) all_number_select.append (number_select) return all_number_select# creates the csv file def add_csv (): df=pd.DataFrame ({"name": pd.Series (create_fname_data ()), "date": pd.Series ("20210101", periods=6)) "mail": pd.Series (create_mail ()),}) print (df) df.to_csv (". / data/random_data.csv") if _ _ name__ = = "_ main__": add_csv () with open (". / data/random_data.csv" Encoding= "utf-8") as name,mail,date # Mail merge data directory location reader=csv.reader (f) next (reader) for index,name,date,mail in reader: doc=MailMerge (". / data/test1.docx") # template file directory print (name,mail,date) doc.merge (name=name,mail=mail Date=date) # Mail merge doc.write (f ". / data/ {name} .docx") # write to the file
The following figure is an automatically generated word document.
After reading this, the article "how to automate office mail merge function in python" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.
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.