Thread

Posted on Wed Nov 23 20:32:19 2005 by mlcohen
Changing style of a cell in a table
Has anybody been able to apply a style to a table cell? I'm comparing two tables (writer, not spreadsheet, not that that should make a difference), and I'd like to colorize the items that are different in the two tables. I'm able to do colorize ordinary text, but not table cells. I've tried all sorts of variations of syntax involving textstyle, setstyle, getcell, getcellparagraphs, setspan, and others, and the only I've been able to do it so far is by editing the content.xml file manually and adding the style information I wanted (which did work). Is this a bug? Am i just getting the syntax wrong? I'm not going to post any code since I've tried tons of different methods.
Thanks,
Matt
Direct Responses: 1396 | Write a response
Posted on Wed Nov 23 22:20:57 2005 by jmgdoc in response to 1394
Re: Changing style of a cell in a table

It's not very easy to know where is the issue without the code and the document ;-)... but, in general terms:
Style of a cell could have 2 different meanings.

"External" layout properties such as border, background color, ... belong to "table-cell" styles. A table cell style may be linked to a given cell using
$doc->cellStyle($cell, "stylename")

"Internal" layout properties, such as font or text alignment belong to an ordinary paragraph style, knowing that the display text of a cell is stored in one or more paragraphs.
The text paragraphs of a given cell may be selected using getCellParagraphs(), then it's easy to give each of them an appropriate style using
$doc->textStyle($para, "stylename")

Note: creating a table cell style from scratch may require a lot of attributes and the presently available createStyle() method is not really designed to hide the complexity of cell styles. The best approach consists of extracting style definitions from a previously hand-written template document (used as a style database). The "prototype" option of createStyle() could be helpful to do that.
Direct Responses: 1397 | Write a response
Posted on Thu Nov 24 00:15:50 2005 by mlcohen in response to 1396
Re: Changing style of a cell in a table
Thanks for the info. That is useful info, but I finally realized the problem when I tried to call tableName() and it didn't work - my IT guys had never installed the latest versions oodoc, so getCellParagraphs() wasn't working (it wasn't working earlier, but I thought that was my fault). When they installed the latest version of oodoc this afternoon, getCellParagraphs() was able to do what I needed.
Thanks,
Matt
Direct Responses: 1561 | Write a response
Posted on Tue Jan 3 17:30:33 2006 by hbarnard in response to 1397
Re: Changing style of a cell in a table
Hi First of all, thanks, this is great! I'm also having some problems with styles:
$style_doc = ooStyles(file => "blank.sxw", member => STYLES); $style_doc->createStyle .... 'Colour'
followed by:
foreach $row ( @$row_ref) { my $text = join(":",@$row[3..5]) ; $doc->textStyle($text,'Colour') ; my $cell = $doc->getCell("Directory$table_counter",$row_counter, $column_counter); $doc->cellValue($cell, $text);
and finally:
$doc->save("directory.sxw"); $style_doc->save("directory.sxw");
gives me nice tabular output but I can't find the custom style anywhere when I unzip directory.sxw and look at it with an editor..and, of course, no custom style applied. I think I've misunderstood (at least) one thing about how to build the structures, but, even after reading the doc, I'm not sure what! Best regards Hugh Barnard
Write a response