了解 Python ReportLab 中的表格坐标系 [英] Understanding Table Coordinate system in Python ReportLab

查看:91
本文介绍了了解 Python ReportLab 中的表格坐标系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解 ReportLab 表格样式的坐标系.

I am having trouble understanding the coordinate system for ReportLab table styles.

根据他们的文档:

每个命令的第一个元素是它的标识符,第二个和第三个参数决定了单元格受负坐标影响的单元格的坐标,从在 Python 索引中限制值.

坐标以 (column, row) 形式给出电子表格A1"模型,但不是更自然的(对于数学家)RC"排序.左上角的单元格是 (0, 0)右下角是 (-1, -1)

如果右下角总是 (-1, -1),这是否意味着中间的行和列是小数?这似乎没有道理.给定下面的例子,从位置 (1,1) 开始的绿色是如何从 0 到 -1 的,以及第二个坐标系 (-2,-2) 如何从原点位置偏移?

If the bottom right is always (-1, -1), does that mean the mid rows and columns are fractional? That doesn't seem to makes sense. Given the below example, how is the green starting at position (1,1) is the coordinate system goes from 0 to -1 and how does the second coordinate system (-2,-2) offset from the origin position?

from reportlab.lib import colors
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle

doc = SimpleDocTemplate("simple_table.pdf", pagesize=letter)
# container for the 'Flowable' objects
elements = []

data= [['00', '01', '02', '03', '04'],
       ['10', '11', '12', '13', '14'],
       ['20', '21', '22', '23', '24'],
       ['30', '31', '32', '33', '34']]
t=Table(data)
t.setStyle(TableStyle([('BACKGROUND',(1,1),(-2,-2),colors.green),
                       ('TEXTCOLOR',(0,0),(1,-1),colors.red)]))
elements.append(t)
# write the document to disk
doc.build(elements)

推荐答案

我终于想通了,所以发布了我自己的答案.您必须考虑完全独立的负坐标系和正坐标系.正系统从左上角的 [1][1] 开始,并随着您向下和向右增加数字.负系统从 [-1][-1] 开始,随着您向上和向左而减少(更大的负值).

I finally figured it out so posting my own answer. You have to think of negative and positive coordinate systems being completely independent of each other. The positive system starts at [1][1] in the top left corner and increments numbers as you go down and to the right. The negative system starts at [-1][-1] as decreases (larger negatives) as you go up and to the left.

在这个例子中,('BACKGROUND',(1,1),(-2,-2),colors.green) 两个坐标,同时使用不同的相对起始位置定义了一个框的左上角和右下角.

In this example, ('BACKGROUND',(1,1),(-2,-2),colors.green) The two coordinates, while using different relative starting position define a the upper left and lower right corners of a box.

这篇关于了解 Python ReportLab 中的表格坐标系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆