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

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

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

序言

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

部分數(shù)據(jù)

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

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

效果展示

數(shù)據(jù)單獨導出為一個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>成車數(shù)量</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ù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

察哈| 京山县| 抚顺市| 台前县| 濮阳县| 上饶市| 无锡市| 双江| 科技| 张家界市| 巴中市| 辉县市| 东明县| 遂宁市| 东乡县| 永宁县| 巴中市| 延寿县| 海兴县| 卢氏县| 化隆| 微山县| 武汉市| 塔城市| 嫩江县| 同心县| 崇礼县| 龙海市| 普宁市| 太谷县| 丹东市| 永嘉县| 西和县| 巴林左旗| 砀山县| 蚌埠市| 闽清县| 缙云县| 正阳县| 花莲县| 平泉县|