自動(dòng)化辦公excel_t_pdf

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>import requests

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>#import xlwt

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>import pdfkit

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>import openpyxl

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>workbook = openpyxl.load_workbook('2020經(jīng)銷商目標(biāo).xlsx')

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>sheet1 = workbook['Sheet1']

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>print(sheet1)

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>html = """

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>><!doctype html>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>><html lang="en">

----------->>>>>>>>>>>>>>>>>>>>>>>>>>><head>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>><title>Document</title>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>><style>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> table {

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> font-size : 22px;

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> width: 850px;

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> }

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> .blod {

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> font_weight: bolder;

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> }

----------->>>>>>>>>>>>>>>>>>>>>>>>>>></style>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>></head>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>><body>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>><table border = "1" align = "center">

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <tr>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <td colspan ="6" align = "center" >2020年廣東經(jīng)銷商預(yù)算目標(biāo)</td>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> </tr>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <tr>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <td>經(jīng)銷商代碼</td>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <td>經(jīng)銷商名稱</td>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <td>成交數(shù)量</td>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <td>成交金額</td>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <td>商品金額</td>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <td>客戶簽字</td>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> </tr>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <tr class = "blod">

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <td>code</td>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <td>name</td>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <td>number</td>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <td>money</td>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <td>total</td>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> <td></td>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> </tr>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>></table>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>></body>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>></html>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>"""

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>for row in list(sheet1.rows)[3:]:

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> for col in row:

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> print(col.value,end='\t')

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> print()

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> code = row[0].value

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> name = row[1].value

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> number = row[2].value

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> money = row[3].value

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> total = row[4].value

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> print(code,name)

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> html = html.replace('code',f'{code}')

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> html = html.replace('name',f'{name}')

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> html = html.replace('number',f'{number}')

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> html = html.replace('money',f'{money}')

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> html = html.replace('total',f'{total}')

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> #print(html)

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> with open('example.html',encoding='utf-8',mode = 'w') as f:

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> f.write(html)

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> #with open('example.html',encoding='utf-8',mode = 'r') as f:

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> # html = f.read()

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> ##--#配置pdf的轉(zhuǎn)化

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> config = pdfkit.configuration(wkhtmltopdf=r'E:\青青教育\前程無憂\wkhtmltopdf\wkhtmltopdf\bin\wkhtmltopdf.exe')

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> #from_file

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> pdfkit.from_file('example.html',f'{name}.pdf',configuration=config)

----------->>>>>>>>>>>>>>>>>>>>>>>>>>>

----------->>>>>>>>>>>>>>>>>>>>>>>>>>> break

-----<Worksheet "Sheet1">

-----2020年廣東經(jīng)銷商預(yù)算目標(biāo) None None None None None

-----None None None None None None

-----經(jīng)銷商代碼 經(jīng)銷商名稱 成交數(shù)量 成交金額 商品金額 客戶簽字

-----AA111 一一一 156 123123 123123 None

-----<Worksheet "Sheet1">

-----None None None None None

-----經(jīng)銷商名稱 成交數(shù)量 成交金額 商品金額 客戶簽字

-----一一一 156 123123 123123 None

def func(money):
#print(money)
str_number = f'{money}'

str_list = list(str_number[::-1])  ##### 順序反轉(zhuǎn)
#print(str_list)
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]

if name == 'main':

#func('24578.13')   24,578,.13
#func('224578') #24,578  224,578
#func('224578')  ,224,578

https://pdf2000.com/converter/exceltopdf/?utm_source=baidunbz02&utm_medium=gj-PDFzh-Excel&utm_campaign=PDFzh-Excel-zh&utm_term=pythonexcelzpdf&e_keywordid=416335210836&e_keywordid2=416335210836&bd_vid=7870719357992339623

https://pdf2000.com/converter/exceltopdf/

https://www.bilibili.com/video/BV1SL411c7oX/?spm_id_from=pageDriver

https://www.bilibili.com/video/BV1SL411c7oX/?spm_id_from=pageDriver

https://www.bilibili.com/video/BV1SL411c7oX/?spm_id_from=pageDriver

https://www.bilibili.com/video/BV1SL411c7oX/?spm_id_from=pageDriver

求助使用python將excel轉(zhuǎn)換成PDF的方法

千次閱讀

2020-12-03 11:11:23

我用的是win32com的三方庫(kù),轉(zhuǎn)換沒有問題,只是excel的內(nèi)容比較多,

最終轉(zhuǎn)換完成后的樣式不是自己需要的,請(qǐng)問ExportAsFixedFormat()方法中有沒有

什么屬性是可以將整個(gè)sheet頁的內(nèi)容轉(zhuǎn)換成一張PDF,求大佬救命。

Import Module

from win32com import client

Open Microsoft Excel

excel = client.Dispatch("Excel.Application")

Read Excel File

sheets = excel.Workbooks.Open('2020經(jīng)銷商目標(biāo).xlsx')
work_sheets = sheets.Worksheets[0]

Convert into PDF File

work_sheets.ExportAsFixedFormat(0, '2020經(jīng)銷商目標(biāo).pdf')

https://www.bilibili.com/video/BV1rr4y187px/?spm_id_from=pageDriver

https://www.bilibili.com/video/BV1Kq4y1C7EJ/?spm_id_from=333.788

python實(shí)戰(zhàn)案例教學(xué):使用 flask 打造視頻搜索網(wǎng)站

https://www.bilibili.com/video/BV1yP4y177ZV/?spm_id_from=333.788

Python爬蟲實(shí)戰(zhàn)教程:突破某點(diǎn)中文網(wǎng)字體反爬技術(shù),獲取網(wǎng)站數(shù)據(jù)

https://www.bilibili.com/video/BV1Vb4y1C7Bo/?spm_id_from=333.788

https://www.bilibili.com/video/BV1Vb4y1C7Bo/?spm_id_from=333.788

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容