Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to achieve batch Export of Excel content to PDF File by Python

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "how to export Excel content to PDF files in batch by Python". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Preface

Partial data

Then you need to install the software wkhtmltopdf.

Effect display

Data is exported separately to a PDF

Implementation code import pdfkitimport openpyxlimport ostarget_dir = 'dealer budget' if not os.path.exists (target_dir): os.mkdir (target_dir) html = "" table {font-size: 22px; font-weight: bolder; width: 850px Guangdong dealer budget target dealer code dealer name car quantity amount of goods customer signature [code] {name} {money} {total} "" def html_to_pdf (filename_html Filename_pdf): "" HTML 2 PDF "" config = pdfkit.configuration (wkhtmltopdf='D:\\ wkhtmltopdf\\ bin\\ wkhtmltopdf.exe') pdfkit.from_file (filename_html, filename_pdf) Configuration=config) wb = openpyxl.load_workbook ('2020 dealer target .xlsx') sheet = wb ['Sheet1'] print (sheet.rows) for row in list (sheet.rows) [3:]: data = [value.value for value in row] data = data [1:-1] format_html = html.replace (' [code]', data [0]) format_html = format_html.replace ('{name}') Data [1]) format_html = format_html.replace ('{number}', str (data [2])) format_html = format_html.replace ('{money}', f' {data [3]: .2f}') format_html = format_html.replace ('{total}', f' {data [4]: .2f}') with open ('example.html', mode='w' Encoding='utf-8') as f: f.write (format_html) html_to_pdf ('example.html', target_dir + os.path.sep + data [0] + "+ data [1] +' .pdf')" how to achieve batch export of Excel content to PDF files by Python "ends here Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report