【问题标题】:how can build invoice like this by Reportlab and pythonReportlab和python如何建立这样的发票
【发布时间】:2016-03-11 17:25:46
【问题描述】:

嗨,我想创建像这张图片一样的发票

我使用Reportlap,对于我的标题我使用SPAN,但我的输出是: 我的代码是:

from reportlab.lib import colors
from reportlab.lib.pagesizes import letter, inch,A5
from reportlab.platypus import Image, Paragraph, SimpleDocTemplate, Table
from reportlab.lib.styles import getSampleStyleSheet

doc = SimpleDocTemplate("complex_cell_values.pdf", pagesize=A5)
elements = []
styleSheet = getSampleStyleSheet()

I = Image('replogo.gif')
I.drawHeight = 1.6*inch
I.drawWidth = 5*inch
data= [['','',I,'',''],
   ['Total Price', 'Price', 'QTY','Description', 'S.No'],
   ['00', 'rial 360,000', '02', '05', '04'],
   ['10', '11', '12', '06', '14'],
   ['20', '21', '22', '23', '24'],
   ['30', '31', '32', '33', '34']]
t=Table(data,style=[('BOX',(0,0),(-1,-1),2,colors.black),
                ('GRID',(0,1),(-1,-1),0.5,colors.black),
                ('SPAN',(0,0),(1,0)),
                ('SPAN',(3,0),(4,0)),
                ('ALIGN',(1,0),(4,-1),'CENTER')
                ])
t._argW[3]=1.5*inch
elements.append(t) 
doc.build(elements)

有人知道我该如何解决这个问题吗?

【问题讨论】:

  • 我找不到 SPAN 参数的文档,但这是我想尝试的。根据this,我会尝试('SPAN',(0,0),(4,0))。只是一个猜测,因此评论而不是答案。
  • 如果我使用 ('SPAN',(0,0),(4,0)) 不能插入任何文本或图像。
  • 好的,这只是一个猜测。我找不到任何文档。假设 SPAN 参数是问题所在,您可以尝试不同的值,看看会发生什么,在网上查找其他示例或访问code 以查看其使用方式。

标签: python python-3.x reportlab


【解决方案1】:

如果我对所有列使用t._argW[X]x=Column,我就能找到答案。

我添加此代码:

t._argW[4]=0.4*inch
t._argW[3]=2*inch
t._argW[2]=0.6*inch
t._argW[1]=1*inch
t._argW[0]=1.3*inch

【讨论】:

    猜你喜欢
    • 2017-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多