In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how Python converts excel content into pdf content in batches. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Project name:
Batch conversion of excel content to pdf
Knowledge points:
Python operation excel
Python operation pdf
Html
Development environment:
Interpreter: Python 3.6.5 | Anaconda, Inc.
Editor: pycharm Community Edition
Code
Import tool
Import openpyxlimport pdfkit
Load a local file
Workbook = openpyxl.load_workbook ('2020 dealer target .xlsx') def func (money): # print (money) str_number = f'{money} 'str_list = list (str_number [::-1]) str_ = "" I = 1 for no, char in enumerate (str_list): str_ + = char # print (no Char) if I% 3 = 0 and len (str_list)! = I: str_ + =','I + = 1 # print (str_ [::-1]) return str_ [::-1] sheet1 = workbook ['Sheet1'] print (sheet1) for row in list (sheet1.rows) [3:]: for col in row [1:]: print (col.value) End='\ t') code = row [1] .value name = row [2] .value number = row [3] .value money = row [4] .value total = row [5] .value print (code, name, number, money) str_number = func (number) str_money = func (money) str_total = func (total) html = html.replace ('code', code) html = html.replace (' name') Name) html = html.replace ('number', f' {str_number} .00') html = html.replace (' money', f' {str_money:} .00') html = html.replace ('total', f' {str_total} .00') # print (html) with open (' example.html', mode='w', encoding='utf-8') as f: f.write (html)
Configure the conversion software for pdf
Config = pdfkit.configuration (wkhtmltopdf='C:\\ Program Files\\ wkhtmltopdf\ bin\\ wkhtmltopdf.exe')
The name of the from_file file saves the name of the file and the configuration of the conversion software
Pdfkit.from_file ('example.html', f' {name} .pdf', configuration=config)
Convert to PDF
Html = "" Document table {font-size: 22px; width: 850px;} .blod {font-weight: bolder 2020 Guangdong dealer budget target dealer code dealer name car quantity amount of goods customer signature code name number money total
Finally, run the code, and the effect is as follows
Thank you for reading! This is the end of this article on "how Python converts excel content into pdf in batches". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.