---- Original message ----
Date: Mon, 03 Jan 2011 01:49:36 -0500
From: Andrew Douglas Pitonyak
<[email protected]>
Subject: Re: [users] Re: API to clone a row in a
writer's table
To: [email protected]
>On 12/31/2010 07:16 AM, Sandro wrote:
>> Thanks Andrew,
>>
>> Andrew Douglas Pitonyak<andrew<at>
pitonyak.org> writes:>
>>
>>> Note that I have not tried anything that I am
about to suggest
>>>
>>> 1. Insert the new row where you desire it to
be.
>>>
>>> 2. Use the view cursor to select the row that
you desire to duplicate.
>>>
>>> 3. Use a dispatch to copy row to the
clipboard.
>>>
>>> 4. Move the view cursor to the new position
and use a dispatch to paste
>>> the row into the new row.
>> after sending this mail I did also investigate
the solution with dispatcher,
>> but I realized I couldn't understand how to
move the viewcursor to the
>> correct location... moreover I mean to use it
in a headless environ and I
>> wasn't sure that this is the best solution.
>
>I expect that in headless mode you will likely
NOT have a view cursor.
>Unfortunately, the view cursor may be the only
way to easily select an
>entire row, but, a cell cursor may also work (I
almost never do this so
>I would need to invest a few hours to understand
it..... I rarely have a
>few hours....)
>
>My best guess without looking anything up
(because it is late and my
>wife told me to come to bed) is that you can use
the current controller
>to select (it should support something like this:
>"currentcontroller.select(oCell)", but, that is
just a guess.
>
>> Anyhow this is what I did:
>>
>>
>> table = document.TextTables.getByIndex(0)
>> cell = table.getCellByPosition(0,1)
>> controller=document.getCurrentController()
>> frame=controller.getFrame()
>> view_cursor=controller.getViewCursor()
>>
>> ... how to move the cursor to the cell??
>>
>> dispatcher = context.ServiceManager.
>>
createInstance('com.sun.star.frame.DispatchHelper')
>>
>> dispatcher.executeDispatch(frame,
'.uno:EntireRow', '', 0, tuple())
>> dispatcher.executeDispatch(frame, '.uno:Copy',
'', 0, tuple())
>> dispatcher.executeDispatch(frame, '.uno:Paste',
'', 0, tuple())
>> dispatcher.executeDispatch(frame,
'.uno:JumpToNextCell', '', 0, tuple())
>
>Yes, I had exactly this sort of thing in mind.
This likely fails in
>headless mode, however. May have to use a cell
cursor or similar.
>Copying arbitrary text, however, is tricky at
best.
>
>>
>>> Note: This will likely fail with a complex
table and special care is
>>> required for complex content (such as when a
cell contains multiple text
>>> objects; for example, an embedded image).
>> The case I'm dealing with now is simple but as
it is part of a template
>> system that is public I can't make assumptions
on how complex will the real
>> templates be.
>
>I disagree. There is no shame in stating that
certain things will ONLY
>work on a simple table (which is the majority
case anyway).
>
>>> I think that new provisions may exist for
copying text content. If that is
>>> the case, you may be able to copy the text
content in each cell to the new
>>> cell in the new row.
>> Can you explain what you mean by "new
provisions may exist for copying text
>> content". I think this is what I was looking
for but I was not able to find
>> a way neather for copying text and style nor
for pasting it!...
>
>In a Calc document, I can specifically say "copy
this range over there"
>without using any other special thing like the
clipboard. For all I know
>that may actually work in text tables as well
since they share many
>similarities to a Calc Sheet (again, I did not
verify). it looks
>something like this:
>
>Sub CopySpreadsheetRange
> REM Get sheet 1, the original, and 2, which will
contain the copy.
> oSheet1 = ThisComponent.Sheets.getByIndex(0)
> oSheet2 = ThisComponent.Sheets.getByIndex(1)
>
> REM Get the range to copy and the rang to copy
to.
> oRangeOrg =
oSheet1.getCellRangeByName("A1:C10").RangeAddress
> oRangeCpy =
oSheet2.getCellRangeByName("A1:C10").RangeAddress
>
> REM The insert position
> oCellCpy =
oSheet2.getCellByPosition(oRangeCpy.StartColumn,_
> oRangeCpy.StartRow).CellAddress
>
> REM Do the copy
> oSheet1.CopyRange(oCellCpy, oRangeOrg)
>End Sub
>
>This may be related to this:
>
>http://api.openoffice.org/docs/common/ref/com/sun/star/text/XTextCopy.html
>
>http://api.openoffice.org/docs/common/ref/com/sun/star/text/XTextTableCursor.html
>
>Never used the XTextCopy, never seen it used.
Perhaps you can ask on the
>[email protected] mailing list.
>>
>> thanks for your time
>> sandro
>> *:-)
>>
>>> On 12/28/2010 11:36 AM, Sandro wrote:
>>>> Hi,
>>>> I already spent many hours on this problem
and I can't find the correct
>>>> approach. I really hope someone can help me
or point me in the correct
>>>> direction/reading.
>>>>
>>>> I need to programmatically duplicate rows of
a Table in openoffice writer.
>>>>
>>>> It's not difficult to add rows via
table.Rows.insertByIndex(idx, count),
>>>> that adds empty rows and it's easy to add
text in that row assigning
>>>> DataArray to the CellRange. Doing this way
you loose control on the style of
>>>> the cells and specifically if a cell has
words with different style
>>>> (bold/italic) they get flattened to the same
face. What I need is to
>>>> duplicate a row in a way that preserves the
style of each word in the
>>>> cell/row.
>>>>
>>>> This is the last step of a Python template
system that uses openoffice
>>>> (http://oootemplate.argolinux.org). I access
the document via 'uno'
>>>> interface in Python but any language would do
to explain the logic behind
>>>> it.
>>>>
>>>> thanks in advance
>>>>
>>>>
>>>> sandro
>>>> *
>>>>
>>>>
>>>>
---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe<at>
openoffice.org
>>>> For additional commands, e-mail:
users-help<at> openoffice.org
>>>>
>>
>>
>>
---------------------------------------------------------------------
>> To unsubscribe, e-mail:
[email protected]
>> For additional commands, e-mail:
[email protected]
>>
>
>--
>Andrew Pitonyak
>My Macro Document:
http://www.pitonyak.org/AndrewMacro.odt
>Info: http://www.pitonyak.org/oo.php
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail:
[email protected]
>For additional commands, e-mail:
[email protected]
>
>