最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實現(xiàn)將Excel內容批量導出為PDF文件

 更新時間:2022年04月16日 09:37:15   作者:嗨學編程  
這篇文章主要為大家介紹了如何利用Python實現(xiàn)將Excel表格內容批量導出為PDF文件,文中的實現(xiàn)步驟講解詳細,感興趣的小伙伴可以了解一下

序言

上一篇咱們實現(xiàn)了多個表格數據合并到一個表格,本次咱們來學習如何將表格數據分開導出為PDF文件。

部分數據

然后需要安裝一下這個軟件 wkhtmltopdf

不知道怎么下載的可以在電腦端左側掃一下找到我要

效果展示

數據單獨導出為一個PDF

實現(xiàn)代碼

import pdfkit
import openpyxl
import os

target_dir = '經銷商預算'

if not os.path.exists(target_dir):
    os.mkdir(target_dir)

html = """
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <style>
        table {
            font-size: 22px;
            font-weight: bolder;
            width: 850px;
        }
    </style>
</head>
<body>
<table border="1" align="center" cellspacing="1">
    <tr>
        <td class='title' align="center" colspan="6">2020年廣東經銷商預算目標</td>
    </tr>
    <tr>
        <td>經銷商代碼</td>
        <td>經銷商名稱</td>
        <td>成車數量</td>
        <td>成車金額</td>
        <td>商品金額</td>
        <td>客戶簽字</td>
    </tr>
    <tr>
        <td>[code]</td>
        <td>{name}</td>
        <td>{number}</td>
        <td>{money}</td>
        <td>{total}</td>
        <td></td>
    </tr>
</table>
</body>
</html>
"""


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經銷商目標.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')

到此這篇關于Python實現(xiàn)將Excel內容批量導出為PDF文件的文章就介紹到這了,更多相關Python Excel導出為PDF內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

阿巴嘎旗| 蒙阴县| 应城市| 兴隆县| 葫芦岛市| 东源县| 正阳县| 汝城县| 宁都县| 元谋县| 林甸县| 嫩江县| 黄山市| 广平县| 时尚| 吉安市| 井冈山市| 天长市| 田阳县| 额尔古纳市| 南木林县| 延川县| 棋牌| 平原县| 东宁县| 墨竹工卡县| 卢龙县| 策勒县| 潼关县| 道孚县| 雅江县| 同江市| 鸡东县| 志丹县| 高安市| 资源县| 抚远县| 张家川| 娱乐| 荆州市| 扶余县|