跳至主要內容
ppt转pdf
import win32com.client
import os
def ppt2pdf(filename, output_filename):
    """
    PPT文件导出为pdf格式
    :param filename: PPT文件的名称
    :param output_filename: 导出的pdf文件的名称
    :return:
    """
    ppt_app = win32com.client.Dispatch('PowerPoint.Application')
    # ppt_app.Visible = True  # 程序操作应用程序的过程是否可视化
    ppt = ppt_app.Presentations.Open(filename)
    # 17数字是ppt转图片,32数字是ppt转pdf
    ppt.SaveAs(output_filename, 32)
    print("导出成pdf格式成功!!!")
    # 退出PPT程序
    ppt_app.Quit()


# 要处理的目录名称
dirname = r''
filenames = os.listdir(dirname)
for filename in filenames:
    if filename.endswith('ppt') or filename.endswith('pptx'):
        base, ext = filename.split('.')
        new_name = base + '.pdf'
        filename =os.path.join(dirname,filename)
        output_filename =os.path.join(dirname,new_name)
        ppt2pdf(filename, output_filename)

爱喝水的木子...小于 1 分钟pythonpptofficepython
生成docx文件
temp_code = {"x":["张三","张三","张三"],"y":["张三","张三","张三"],"z":["张三","张三","张三"]}
import json

from docx import Document
from docx.oxml.ns import qn
from docx.shared import Pt, RGBColor


def create_docx(doc_name, text_list):
    doc = Document()
    doc.styles['Normal'].font.name = u'宋体'
    doc.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
    doc.styles['Normal'].font.size = Pt(10.5)
    doc.styles['Normal'].font.color.rgb = RGBColor(0, 0, 0)
    for item in text_list:
        doc.add_paragraph(item)
    doc.save(doc_name)
for k, v in temp_code.items():
    _doc_name = k + ".docx"
    create_docx(_doc_name, v)

爱喝水的木子...小于 1 分钟pythonpptofficepython