[reportlab-users] Tables and spanning

Johan Paul Glutting reportlab-users@reportlab.com
Thu, 30 Sep 2004 09:02:01 +0200


Thanks for the email, Andy. It was a great summary of the spanning 
format. I pretty much understand how it works.
I rummaged around in the source code and started to try some things 
myself, but I can't seem to span a cell across two columns (or more 
precisely, I can't span across the two columns I want to span - the 
indexing is off to the left or to the right no matter what I put into 
the code - very strange....). I did get a very simple example to work 
correctly.

My code takes data from a postgres database and formats the results, so 
I will dummy up some code to send you. At first, I tried to do a series 
of horizontal spans, as well as several vertical spans, but I finally 
reduced it to just one horizontal span, and even that does not work. I 
set the format to create a grid, so that I can see which cells are 
spanned ...

Update: While trying to create a simple example, I have found again that 
spanning works correctly with this data. What is happening in the actual 
production table is that it is spanning, but it is not writing over the 
"spanned" cell, just merging all the text into a single cell (it is also 
spanning three cells instead of two). I am going to work on my script a 
bit more (which involves extra classes and other types of formating) to 
see if I can pinpoint the part that is creating the confusion.

JP

PS My "test_platypus_tables.py" script creates a file called 
"test_platypus_tables.pdf" in the same directory, but none of the tables 
in that file seem to use spanning - in fact, there is no 'SPAN' format 
definition in this script. The term "span" only appears in this 
directory in a file called "test_pdfgen_pycanvas_out.txt". Did you mean 
to refer to another script or directory? I am using reportlab version  
1.27, I believe.

PPS  The spanning seems to work pretty well, if I can get it to do what 
I ask it to do. What exactly would be the difference/advantage of 
"HTML-like" cell spanning?

En/na Andy Robinson ha escrit:

>>I am having very serious trouble trying to get cells to span using the 
>>table code in reportlab. The main problem seems to be that the code 
>>cannot  span the cells that I am interested in. I am beginning to think 
>>the problem is that the cell spanning screws up the indexing of the 
>>table, so trying to span more than once in a given row creates 
>>confusion. It also seems to try to span three columns when I ask for two.
>>    
>>
>
>  
>
>> From what I have gathered from some posts on this list is that this 
>>code is not really working properly. Has anyone used column spanning, 
>>and is there any limited functionality that works ?
>>    
>>
>
>AFAIK it works exactly as ReportLab's staff expect it to, but nothing
>like HTML, and it may probably needs better explanation.   We use it all 
>the time via Report Markup Language. There is a test script 
>reportlab_platypus_tables.py which (rather confusingly I admit) creates 
>a file in the temp output directory 'tables.pdf'; studying this should
>help.
>
>Here's an example from that test script:
>    data=  [['A', 'BBBBB', 'C', 'D', 'E'],
>            ['00', '01', '02', '03', '04'],
>            ['10', '11', '12', '13', '14'],
>            ['20', '21', '22', '23', '24'],
>            ['30', '31', '32', '33', '34']]
>    sty = [
>            ('ALIGN',(0,0),(-1,-1),'CENTER'),
>            ('VALIGN',(0,0),(-1,-1),'TOP'),
>            ('GRID',(0,0),(-1,-1),1,colors.green),
>            ('BOX',(0,0),(-1,-1),2,colors.red),
>
>            #span 'BBBB' across middle 3 cells in top row
>            ('SPAN',(1,0),(3,0)),
>
>Our grid commands come in two flavours.  The ones relating
>to drawing lines refer to the 'slices between the cells',
>just like Python list slicing (only 2d).  The ones relating
>to 'cells themselves' such as color, font size and spanning
>all count the cells starting from zero.  So the command here
>            ('SPAN',(1,0),(3,0)),
>says to merge the SECOND through FOURTH cells in the top row
>and merges them.  This means that we draw what would have been
>in the top left cell in the spanned range ('BBBB') across three
>cells, and don't draw the 'C' and 'D'.
>
>You have to understand that our commands about table ranges
>are not like HTML; they live 'in the style' not 'on the cell'.
>This was the easiest implementation given what we'd already built.
>It also makes it easy to create a top or bottom or left row in a table
>style which 'does the right thing' even though the number of columns
>and rows may vary.
>
>We have one major limitation with this model:  currently the
>line-drawing commands don't take account of spanned cells. So
>if you ask for a grid, it will slice across the spanned cell.
>Resolving this would take a lot more computation - we'd need to
>compute every edge of every cell. In real-world use this has
>not been a problem as we just don't tell it to draw through 
>the spans.
>
>As always, I will reiterate that I'd welcome a contributed HTML-like
>table class.  But it isn't an easy job ;-)
>
>And if you've got a case which isn't working, send it over.
>
>I hope this helps,
>
>Andy Robinson
>
>
>
>_______________________________________________
>reportlab-users mailing list
>reportlab-users@reportlab.com
>http://two.pairlist.net/mailman/listinfo/reportlab-users
>  
>


-- 
JP Glutting
Oficina de Qualitat		Plaça Víctor Siurana, 1
Universitat de Lleida		25003 Lleida
-------------------------------------------------------
Tel: 973 703 103		Fax: 973 702 036