last and final attempt to search for python ods library.

Terry Reedy tjreedy at udel.edu
Tue Mar 10 05:27:36 CET 2009


John Machin wrote:
> On Mar 10, 6:55 am, Terry Reedy <tjre... at udel.edu> wrote:
>> Krishnakant wrote:
>>> I need to merge cells in a spreadsheet and this library won't do that.
>> I think you are confusing process and result.  The result is a cell that
>> spans more than one column or row *when displayed*, thus hiding the
>> cells that would otherwise be displayed. This is, I am 99.9% sure,
>> controlled by an attribute of the visually expanded cell.
>>
>> In OOCalc, the process is to mark a block of cells and select Format /
>> Merge Cells.  But still, the result will be a change in the upper left
>> attribute.  Thus I suggested you make a .ods file with expanded cells
>> and then read the xml to see what cell element attribute is set thereby.
>> Any decent odf library will be able to set element attributes.
> 
> It doesn't appear to be quite so simple.
> 
> ODS uses a <table:table-cell> element as usual for the upper left
> cell. Attributes set the range e.g. table:number-columns-spanned="3"
> table:number-rows-spanned="2"
> 
> The gotcha is that it uses a *different* element for the cells covered
> by the range. Example:
> <table:covered-table-cell table:number-columns-repeated="2" />
> 
> This is looks like structural amendments are needed to a package like
> (python-)?ooolib(-python)? that doesn't grok merged cells -- its
> source doesn't contain the string "covered". Doesn't seem like it
> could be done just by poking in attributes.

I guess it makes some sense that a cell that gets covered should be 
changed to a covered-cell rather than merely being marked as 'covered' 
or the covering left implicit by position.  This would make it easier 
for display software.

In any case, api-for-odfpy.odt has

5.17.12 table.CoveredTableCell
Requires the following attributes: No attribute is required.
Allows the following attributes: booleanvalue, contentvalidationname, 
currency, datevalue, formula, numbercolumnsrepeated, protect, 
stringvalue, stylename, timevalue, value, valuetype.
These elements contain table.CoveredTableCell: table.TableRow.
The following elements occur in table.CoveredTableCell: dr3d.Scene, 
draw.A, draw.Caption, ...

so odfpy, at least, can create such elements.

> 
> Here's an example of 2 merged ranges: A1:C2 contains the text "foo"
> and D1:D2 contains "bar"
> 
> <table:table-row table:style-name="ro1">
> - <table:table-cell table:style-name="ce1" office:value-type="string"
> table:number-columns-spanned="3" table:number-rows-spanned="2">
>   <text:p>foo</text:p>
>   </table:table-cell>
>   <table:covered-table-cell table:number-columns-repeated="2" />
> - <table:table-cell table:style-name="ce1" office:value-type="string"
> table:number-columns-spanned="1" table:number-rows-spanned="2">
>   <text:p>bar</text:p>
>   </table:table-cell>
>   </table:table-row>
> - <table:table-row table:style-name="ro1">
>   <table:covered-table-cell table:number-columns-repeated="4" />
>   </table:table-row>
> 
> Aside: If you are wondering where the cell addresses (D1 etc) are,
> they're in the reader's current_row and current_col variables :-)
> Perhaps this was intended to save space, but what of table:number-
> columns-repeated="4" ??

Those are the 4 cell covered in the second row -- 3 by 'foo' and 1 by 
'bar'.  I believe there could have been two separate entries, but this 
is more compact, if less clear ;-)

Terry Jan Reedy




More information about the Python-list mailing list