docx

将.docx文件转化为.pdf文件

邮差的信 提交于 2019-11-25 22:31:23
将.docx文件转化为.pdf文件 在需要转化.docx为.pdf的文件夹中打开powershell然后运行该程序,可以将文件夹下所有.docx文件转化为.pdf文件。 from win32com.client import Dispatch, constants, gencache import os def doc2pdf(docPath, pdfPath): docPathTrue = os.path.abspath(docPath) pdfPathTrue = os.path.abspath(pdfPath) #word = gencache.EnsureDispatch('Word.Application') word = Dispatch('Word.Application') doc = word.Documents.Open(docPathTrue, ReadOnly=1) doc.ExportAsFixedFormat(pdfPathTrue, constants.wdExportFormatPDF, Item=constants.wdExportDocumentWithMarkup, CreateBookmarks=constants.wdExportCreateHeadingBookmarks) word.Quit(constants

获取docx文件中表格的内容

删除回忆录丶 提交于 2019-11-25 19:06:37
# -*- coding: UTF-8 -*- import re import linecache import docx import sys import docx from docx import Document #导入库 path = "D:\\文件\\政策汇\\有用\\untitled3\\docx\\printout.docx" #文件路径 document = Document(path) #读入文件 tables = document.tables #获取文件中的表格集 table = tables[0]#获取文件中的第一个表格 result = [] for i in range(1,len(table.rows)):#从表格第二行开始循环读取表格数据 # result = table.cell(i,0).text + " " +table.cell(i,1).text + " "+table.cell(i,2).text +" "+ table.cell(i,3).text #cell(i,0)表示第(i+1)行第1列数据,以此类推 for a in range(0,len(table.columns)): result= table.cell(i,a).text print(result) 来源: https://www.cnblogs.com/zyl