技术标签: python生成pdf报告模块
from reportlab.platypus importSimpleDocTemplate, Paragraph, Spacer, Image, PageBreak, Table, TableStylefrom reportlab.lib.styles importParagraphStyle, getSampleStyleSheetfrom reportlab.lib.units importmmfrom reportlab.lib importcolorsfrom reportlab.lib.enums importTA_CENTER, TA_LEFTfrom reportlab.pdfbase importpdfmetricsfrom reportlab.pdfbase.ttfonts importTTFont
pdfmetrics.registerFont(TTFont('pingbold', 'PingBold.ttf'))
pdfmetrics.registerFont(TTFont('ping', 'ping.ttf'))
pdfmetrics.registerFont(TTFont('hv', 'Helvetica.ttf'))#生成PDF文件
classPDFGenerator:def __init__(self, filename):
self.filename=filename
self.file_path= '/xxx/xxx/xxx/xxx/'self.title_style= ParagraphStyle(name="TitleStyle", fontName="pingbold", fontSize=48, alignment=TA_LEFT,)
self.sub_title_style= ParagraphStyle(name="SubTitleStyle", fontName="hv", fontSize=32,
textColor=colors.HexColor(0x666666), alignment=TA_LEFT, )
self.content_style= ParagraphStyle(name="ContentStyle", fontName="ping", fontSize=18, leading=25, spaceAfter=20,
underlineWidth=1, alignment=TA_LEFT, )
self.foot_style= ParagraphStyle(name="FootStyle", fontName="ping", fontSize=14, textColor=colors.HexColor(0xB4B4B4),
leading=25, spaceAfter=20, alignment=TA_CENTER, )
self.table_title_style= ParagraphStyle(name="TableTitleStyle", fontName="pingbold", fontSize=20, leading=25,
spaceAfter=10, alignment=TA_LEFT, )
self.sub_table_style= ParagraphStyle(name="SubTableTitleStyle", fontName="ping", fontSize=16, leading=25,
spaceAfter=10, alignment=TA_LEFT, )
self.basic_style= TableStyle([('FONTNAME', (0, 0), (-1, -1), 'ping'),
('FONTSIZE', (0, 0), (-1, -1), 12),
('ALIGN', (0, 0), (-1, -1), 'LEFT'),
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
('BOTTOMPADDING', (0, 0), (-1, -1), 6),#'SPAN' (列,行)坐标
('SPAN', (1, 0), (3, 0)),
('SPAN', (1, 1), (3, 1)),
('SPAN', (1, 2), (3, 2)),
('SPAN', (1, 5), (3, 5)),
('SPAN', (1, 6), (3, 6)),
('SPAN', (1, 7), (3, 7)),
('GRID', (0, 0), (-1, -1), 0.5, colors.black),
])
self.common_style= TableStyle([('FONTNAME', (0, 0), (-1, -1), 'ping'),
('FONTSIZE', (0, 0), (-1, -1), 12),
('ALIGN', (0, 0), (-1, -1), 'LEFT'),
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
('BOTTOMPADDING', (0, 0), (-1, -1), 6),
('GRID', (0, 0), (-1, -1), 0.5, colors.black),
])defgenTaskPDF(self, home_data, task_data, basic_data, case_set_data, fail_case_data, p0_case_data):
story=[]#首页内容
story.append(Spacer(1, 20 *mm))
img= Image('/xxx/xxx.png')
img.drawHeight= 20 *mm
img.drawWidth= 40 *mm
img.hAlign=TA_LEFT
story.append(img)
story.append(Spacer(1, 10 *mm))
story.append(Paragraph("测试报告", self.title_style))
story.append(Spacer(1, 20 *mm))
story.append(Paragraph("Test Report of XXX", self.sub_title_style))
story.append(Spacer(1, 45 *mm))
story.append(Paragraph("报告编号:" + home_data['report_code'], self.content_style))
story.append(Paragraph("计划名称:" + home_data['task_name'], self.content_style))
story.append(Paragraph("报告日期:" + home_data['report_date'], self.content_style))
story.append(Paragraph("负责人:" + home_data['report_creator'], self.content_style))
story.append(Spacer(1, 55 *mm))
story.append(Paragraph("内部文档,请勿外传", self.foot_style))
story.append(PageBreak())#表格允许单元格内容自动换行格式设置
stylesheet =getSampleStyleSheet()
body_style= stylesheet["BodyText"]
body_style.wordWrap= 'CJK'body_style.fontName= 'ping'body_style.fontSize= 12
#测试计划
story.append(Paragraph("测试计划", self.table_title_style))
story.append(Spacer(1, 3 *mm))
task_table= Table(task_data, colWidths=[25 * mm, 141 * mm], rowHeights=12 * mm, style=self.common_style)
story.append(task_table)
story.append(Spacer(1, 10 *mm))#基础参数
story.append(Paragraph("基础参数", self.sub_table_style))
basic_table= Table(basic_data, colWidths=[25*mm, 61*mm, 25*mm, 55*mm], rowHeights=12 * mm, style=self.basic_style)
story.append(basic_table)
story.append(Spacer(1, 10 *mm))#测试用例集
story.append(Paragraph("用例集参数", self.sub_table_style))
case_set_table= Table(case_set_data, colWidths=[25 * mm, 141 * mm], rowHeights=12 * mm, style=self.common_style)
story.append(case_set_table)#story.append(PageBreak())
story.append(Spacer(1, 15 *mm))#失败用例--使用可以自动换行的方式需要data里都是str类型的才OK
story.append(Paragraph("失败用例", self.table_title_style))
story.append(Spacer(1, 3 *mm))
para_fail_case_data= [[Paragraph(cell, body_style) for cell in row] for row infail_case_data]
fail_case_table= Table(para_fail_case_data, colWidths=[20 * mm, 35 * mm, 91 * mm, 20 *mm])
fail_case_table.setStyle(self.common_style)
story.append(fail_case_table)
story.append(Spacer(1, 15 *mm))#基础用例(P0)
story.append(Paragraph("基础用例(P0)", self.table_title_style))
story.append(Spacer(1, 3 *mm))
para_p0_case_data= [[Paragraph(cell, body_style) for cell in row] for row inp0_case_data]
p0_case_table= Table(para_p0_case_data, colWidths=[20 * mm, 35 * mm, 91 * mm, 20 *mm])
p0_case_table.setStyle(self.common_style)
story.append(p0_case_table)
doc= SimpleDocTemplate(self.file_path + self.filename + ".pdf",
leftMargin=20 * mm, rightMargin=20 * mm, topMargin=20 * mm, bottomMargin=20 *mm)
doc.build(story)
文章浏览阅读661次。Metrics are the heart of Sonar, using Sonar efficiently means perfectly understanding the definition and calculation algorithm of each one.Name Key Description Physical lineslinesNumbe..._sonar duplicated lines
文章浏览阅读2.1w次,点赞141次,收藏384次。运动规划是自动驾驶的核心理论和工程技术之一,本文作为教程先导,解析了运动规划的两大组件——路径规划和轨迹规划。欢迎感兴趣的同学订阅专栏!_motion planner c++
文章浏览阅读2.1k次。关联关系大体分三类:一对一,一对多和多对多。一对一 在实际项目中,几乎没有用不到一对一关系映射的,对一对一关系最好使用唯一主外键关联,即两张表使用外键关联关系,同时给外键列增加唯一约束。示例(公民和身份证)public class Card{//身份证类 private int id; private String code; _ssm中可以省去映射关系吗
文章浏览阅读93次。这里仍然以微博为例,接下来用Python来模拟这些Ajax请求,把我发过的微博爬取下来。1. 分析请求打开Ajax的XHR过滤器,然后一直滑动页面以加载新的微博内容。可以看到,会不断有Ajax请求发出。选定其中一个请求,分析它的参数信息。点击该请求,进入详情页面,如图6-11所示。图6-11 详情页面可以发现,这是一个GET类型的请求,请求链接为[https://m.weibo.cn/api/co...
文章浏览阅读6.9k次。在c_cpp_properties.json中,将"compilerPath"中的值修改为launch.json中的编译器路径。_环境变量“${env.include}”求值失败
文章浏览阅读2k次。进程间通信的基本概念进程间通信意味着两个不同进程间可以交换数据,但从上一章节我们知道,不同进程间内存是相互独立的,那么要实现不同进程间通信,就得有一个它们都能访问的公共区域内存做媒介,这个媒介不属于进程,而是和套接字一样,属于操作系统。所以,两个进程通过操作系统提供的内存空间进行通信,我们把这块内存空间称作管道。 创建管道函数 int pipe(int filedes[2]); 成功_tpc/ip 和进程通信
文章浏览阅读460次。https://bitable.feishu.cn/app8Ok6k9qafpMkgyRbfgxeEnet?from=logout&table=tblEnSV2PNAajtWE&view=vewJHSwJVd_会 80% 直接进大厂
文章浏览阅读2.6k次。实验6:存储过程实验环境:SQL Server(1)实验目的掌握数据库PL/SQL编程语言,以及数据库存储过程的设计和使用方法。(2)实验内容和要求存储过程定义、存储过程运行,存储过程更名,存储过程删除,存储过程的参数传递。掌握PL/SQL编程语言和编程规范,规范设计存储过程。(3)实验重点和难点实验重点:存储过程定义和运行。实验难点:存储过程的参数传递方法。(4)实验过程SQL是非过程化的查询语言,具有操作统一、面向集合、功能丰富、使用简单等优点,但和程序设计语言相比,高度非过程化造成_数据库实验六存储过程
文章浏览阅读8.1k次。最近几年随着互联网时代的发展,做电影网站的站长越来越多了,加入此行列的人也是与日俱增!但是很多站长都是跟风来做电影站的,怎么做一点思路都没有。电影资源都不知道怎么来的。今天就教大家怎么做好电影站,文章有点长请大家耐心观看,快速解决影视站遇到的所有问题!一、苹果采集插件接口配置1、今天教大家怎么添加采集自定义资源库;进入后台我们随便以某资源站为例,接口可以到你要采集的网站上获取就可以了 一般都在网站的帮助中心:添加方法如下图(添加后进行测试不成功需要填写附加参数 &ct=1)2、._苹果cms采集插件
文章浏览阅读629次。1.下载VC6LineNumberAddin插件及注册文件。(以下是参考链接:)http://codefish.googlecode.com/files/VC%E6%98%BE%E7%A4%BA%E8%A1%8C%E5%8F%B7_VC6LineNumberAddin.rar2.解压把拷贝VC6LineNumberAddin.dll到VC6安装路径下的AddIns文件夹,笔者的完整路径_vc6linenumberaddin.exe
文章浏览阅读812次。error C4800: 从“const wchar_t *”到 bool 的隐式转换。信息可能丢失在VCToolChain.cs 484行添加下面的 Arguments.Add("/TP"); Arguments.Add("/wd4800");include <typeinfo.h> error修改为include <typeinfo>_error c4800: 从“gamestore *”到 bool 的隐式转换。信息可能丢失
文章浏览阅读8k次,点赞9次,收藏55次。英文名:Huawei Certified ICT Expert-Datacom中文名:培训与认证数通网络领域具备跨场景融合解决方案专业知识和技能水平的专家考华为认证想刷题,用这个工具就可以了_哔哩哔哩_bilibili。_网络调优计算即选择合适的调优目的,应用相应的算法,全局或局部地计算优化路径。控