I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2010-05-05 01:58:40.012325-07 by bene
Problems inserting a blank new Row into a table in OpenOffice Writer
I've browsed all entries of this forum but haven't found any hint to save my problem: My OO-Writer document has a two-column table, which creates of log, the first column is a date and the second column consists of entries made by users in native OO. I use the following code to insert an new table row at the top of the table:
# Insert a new table Row $doc->insertRow($Tablename, 0) ; # the new row is inserted, but it isn't blank, it is a copy of the next row, # so update the first cell with actual date: $doc->cellValue($Tablename, 0, 0, $DateTimeString) ; # and blank the second cell: $doc->cellValue($Tablename,0,1,"") ;
Here is my problem:

If the second column of the old first Row, which is Cell (0,1) consists of a multiline entry, for example:

Line1

Line2

Line3

this entry is duplicated by insertRow, but when I try to blank the new Cell with
$doc->cellValue($Tablename,0,1,"") ;
only the first line of the Cell is blanked, so I get as new entry:

(blank line)

Line2

Line3

How can I blank the whole new cell?

Have I missed something?

Siegfried

Direct Responses: 12680 | Write a response
Posted on 2010-05-05 03:04:55.398989-07 by jmgdoc in response to 12679
Re: Problems inserting a blank new Row into a table in OpenOffice Writer

The insertRow method creates a row that replicates an existing row; it's a design choice, in order to avoid requiring a lot of parameters specifying the configuration of the new row.


The text content of a cell is hosted in one or more paragraphs. The cellValue (or setText, when applied to a table cell) method updates the first paragraph of the target cell. The subsequent paragraphs, if any, remain unchanged. Note that this feature allows the user to individually select/update/delete a particular paragraph in a cell.

As a consequence, all the embedded paragraphs must be explicitly removed in order to clear a cell as soon as it's suspected to be a multi-paragraph one.

We can use getCellParagraphs in order to get the list, then delete each paragraph using removeElement. Example:

$doc->removeElement($_) for $doc->getCellParagraphs($table, $row, $position);

Alternatively, we can use cut_children from the cell element. This method is not documented with OpenOffice::OODoc, but it's inherited from XML::Twig. It deletes all the elements contained in the calling element; so when used from a cell element it removes everything in the cell. Example:

$doc->getCell($table, $row, $position)->cut_children;
Direct Responses: 12681 | Write a response
Posted on 2010-05-05 04:28:40.303192-07 by bene in response to 12680
Re: Problems inserting a blank new Row into a table in OpenOffice Writer

Thanks for the explanation.

Since my first post, I found out that
my $_cell = $doc->getCell($Tablename, 0, 1); $doc->removeParagraph($_cell);
works as well.

Siegfried

Direct Responses: 12682 | Write a response
Posted on 2010-05-05 06:01:48.506766-07 by jmgdoc in response to 12681
Re: Problems inserting a blank new Row into a table in OpenOffice Writer

Be careful, removeParagraph may work is some situations but it doesn't produce exactly the same effect as an explicit removal of the paragraphs under the cell...
Direct Responses: Write a response