需要使用报告实验室库在单个pdf页面中并排对齐两个输出表
我已经使用cx_Oracle库从Oracle Sql开发人员创建了两个输出表,并使用reportlab软件包将这些表导出到单个pdf页面中
# Importing packages
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.platypus import *
from reportlab.lib import colors
import pandas as pd
from reportlab.lib.pagesizes import letter, A3, inch
# Creating a sample doc and setting up the path
PATH_OUT = (r"directory_path")
elements = []
styles = getSampleStyleSheet()
doc = SimpleDocTemplate(PATH_OUT + 'Report_File.pdf', pagesize = A3)
elements.append(Paragraph("Report_name", styles['Title']))
# Importing numpy for converting df to list to avoid data type errors
import numpy as np
t1 = Table(np.array(data_test).tolist())
t2 = Table(np.array(data_test1).tolist())
# Creating data styling for two tables
t1.setStyle(TableStyle([('ALIGN', (1,1), (-1,-1), 'CENTER'),
('FONT', (0,0), (-1,0), 'Times-Bold'),
('FONT', (0,-1), (-1,-1),'Times-Bold'),
('TEXTCOLOR',(0,0),(1,-1),colors.black),
('TEXTCOLOR',(0,0),(-1,0),colors.white),
('GRID', (0,0), (-1,-1), 0.50, colors.grey),
('LINEABOVE', (0, -1), (-1,-1), 2, colors.grey),
('LINEBELOW',(1,-1), (-1, -1), 2, (0.5, 0.5, 0.5)),
t2.setStyle(TableStyle([('ALIGN', (1,1), (-2,-2), 'CENTER'),
('FONT', (0,0), (-1,0), 'Times-Bold'),
('FONT', (0,-1), (-1,-1),'Times-Bold'),
('TEXTCOLOR',(0,0),(1,-1),colors.black),
('TEXTCOLOR',(0,0),(-1,0),colors.white),
('GRID', (0,0), (-1,-1), 0.50, colors.grey),
('LINEABOVE', (0, -1), (-1,-1), 2, colors.grey),
('LINEBELOW',(1,-1), (-1, -1), 2, (0.5, 0.5, 0.5)),
('BACKGROUND',(0,0),(-1,0),colors.HexColor("#f24dae")),]))
# Appending two tables in a single page
elements.append(t1)
elements.append(t2)
doc.build(elements)
实际输出表彼此对齐,但所需的输出在表之间应有一定的间隙,并应在单个pdf页中并排对齐
我正在研究时间敏感的作品,因此,响应速度更快将不胜感激:)