def create_input_pdf(user, data_list): '''列表生成pdf文件''' c = canvas.Canvas(PathManage.doc_path(f'{user}.pdf')) pdfmetrics.registerFont(TTFont('msyh', PathManage.db_path('msyh.ttf'))) c.setFont('msyh', 12) textobject = c.beginText() textobject.setTextOrigin(inch, 11 * inch) now = datetime.datetime.today() # 设定日期格式 date = now.strftime('%Y-%m-%d %H:%M:%S') # 设置下载时间 textobject.textLines(f'下载时间:{date}'.center(80, '-')) for i in range(0, len(data_list)): data_str = data_list[i] text_memo = f'{i+1}' + '. ' + data_str # num = 1 # for k, v in data_dict.items(): # if num == len(data_dict): # text_memo += f'{k}: {v} 。' # num += 1 # else: # text_memo += f'{k}: {v} ,' # num += 1 getDate = GetDate() getDate.get_data(text_memo, 60) text_list = getDate.text_list for text in text_list: textobject.textLines(text) c.drawText(textobject) c.showPage() c.save()
def save_to_excel(self, excel_filename): excel = Excel() excel.add_sheet_method('pic data', 0) sheet = excel.get_sheet_method('pic data') sheet.cell(row=1, column=1).value = '文件名' sheet.cell(row=1, column=2).value = '文件大小' file_name = [] file_size = [] for file in self.files: print(file) if re.match('(.*png)|(.*bmp)|(.*jpg)$', file): name = file.split('\\')[-1] file_name.append(name) size = DirUtil.get_file_size(file) file_size.append(size) if len(file_name): if len(file_name) > 2: for row in range(2, len(file_name) + 2): sheet.cell(row=row, column=1).value = file_name[row - 2] sheet.cell(row=row, column=2).value = file_size[row - 2] else: sheet.cell(row=2, column=1).value = file_name[0] sheet.cell(row=2, column=2).value = file_size[0] excel.excel_save(PathManage.doc_path(excel_filename))
def main(): love = LoveLetter() love.add_title_method('这是一个love模板') love.add_lover_method('玲玲') love.add_paragraph_method('正文' * 10) love.add_heart_method() love.add_sign_method('张三') love.save_method(PathManage.doc_path('love.docx'))
def main(): docAdmin = Word() # print(docAdmin.ret) docAdmin.add_head_method('这是标题', 0) # print(docAdmin.ret) heart_path = PathManage.pic_path('heart.jpg') docAdmin.add_pic_method(heart_path) # print(docAdmin.ret) docAdmin.add_paragraph_method('这是副标题', 'Subtitle') p2 = docAdmin.add_paragraph_method('这是普通文字,这是普通文字,这是普通文字,这是普通文字,这是普通文字') docAdmin.add_style_method(p2, 'Title') print(type(p2)) p2_words = docAdmin.add_paragraph_words_method(p2, '这是追加的文字') # docAdmin.add_fontSize_method(p2,33) print(type(p2_words)) print(docAdmin.ret) doc_path = PathManage.doc_path('loveletter.docx') docAdmin.save_method(doc_path)
import os import sys dir_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(dir_path) from docx.enum.style import WD_STYLE_TYPE from docx import * from utils.path_manage import PathManage document = Document() styles = document.styles #生成所有段落样式 for s in styles: if s.type == WD_STYLE_TYPE.PARAGRAPH: document.add_paragraph('Paragraph style is : ' + s.name, style=s) document.save(PathManage.doc_path('para_style.docx'))
import os import sys dir_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(dir_path) from docx.enum.style import WD_STYLE_TYPE from docx import * from utils.path_manage import PathManage document = Document() styles = document.styles para = document.add_paragraph() #生成所有字符样式 for s in styles: if s.type == WD_STYLE_TYPE.CHARACTER: run = para.add_run("Character style is: " + s.name + "\n") run.style = s document.save(PathManage.doc_path('character_style.docx'))
import os import sys dir_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(dir_path) from docx.enum.style import WD_STYLE_TYPE from docx import * from utils.path_manage import PathManage document = Document() styles = document.styles #生成所有表样式 for s in styles: if s.type == WD_STYLE_TYPE.TABLE: document.add_paragraph("Table style is : " + s.name) document.add_table(3, 3, style=s) document.add_paragraph("\n") document.save(PathManage.doc_path('db.docx'))