[Solved] Copying some Doc into an other one

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
Peter18
Posts: 102
Joined: Thu May 12, 2011 1:01 pm

[Solved] Copying some Doc into an other one

Post by Peter18 »

A friendly hallo to anybody

again I have a problem. I looked through the documentation to solve it. May be I looked at the solution, but I did not see it!
I hope someone can destroy the wall.

I want to open some Docs and copy the entire content with formating and insert it into an other. So at least the new Doc shall contain the content of all the other Docs. If I record a macro, the result is this:

Code: Select all

dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SelectAll", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
Because I want to do this with Delphi I do not prefer the dispatcher. Creating a cursor and get a range from begin to end is no problem. But how to get the content with graphics, tabels and formatings and insert it at the end of the new doc! It looks like I get all the objekts with the cursor, but I did not find a method to insert it.
Because the Docs are created temorarly I can not use "insertDocumentFromURL".

I hope some one can help me and thank you for trying it.

Peter
Last edited by Hagar Delest on Thu Jan 26, 2012 10:39 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 3.3; OpenOffice 4.1.1
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Copying some Doc into an other one

Post by Villeroy »

Peter18 wrote: Because I want to do this with Delphi I do not prefer the dispatcher.
Why don't you use the API then?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Peter18
Posts: 102
Joined: Thu May 12, 2011 1:01 pm

Re: Copying some Doc into an other one

Post by Peter18 »

Hallo Villeroy,
Villeroy wrote:Why don't you use the API then?
That's what I want to do!

Peter
OpenOffice 3.3; OpenOffice 4.1.1
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Copying some Doc into an other one

Post by Villeroy »

Good choice.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Peter18
Posts: 102
Joined: Thu May 12, 2011 1:01 pm

Re: Copying some Doc into an other one

Post by Peter18 »

Hello Villeroy,

thank you, it was very helpfull!!!

Peter
OpenOffice 3.3; OpenOffice 4.1.1
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Copying some Doc into an other one

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Peter18
Posts: 102
Joined: Thu May 12, 2011 1:01 pm

Re: Copying some Doc into an other one

Post by Peter18 »

Hello Villeroy,

thank you for your answer. But I'm sorry it did not really help. Up to now I am not very familiar with the OO-documentation. The description ist extremly short, so it is very difficult to understand what a method is doing. And often I have got a problem to find out in what context I'll find it.

So, please give me an example, I can put into a macro and try. So I can learn to read the OO-documentation. And I can test out how the program does, what I want it to do.

Greetings from the north see

Peter
OpenOffice 3.3; OpenOffice 4.1.1
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Copying some Doc into an other one

Post by Villeroy »

The dispatches to control the user interface will definitively work.
For the rest you have something to google for.
Typing "transferable" into this site's search box: http://user.services.openoffice.org/en/ ... le#p162730
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: Copying some Doc into an other one

Post by rudolfo »

Peter18 wrote:Because the Docs are created temporarily I can not use "insertDocumentFromURL".
As you have learned now that the approach with the clipboard or text cursors and copying the content by pieces is complicated you should reconsider if you really cannot use insertDocumentFromURL.
It is actually the interface and method that suits best for what you want to do. Better invest your thinking into how to get proper serialization, file locking and unique temporary file names and then use the file name together with insertDocumentFromURL.
This has the big advantage that you can do this in your familiar Delphi environment. As any good programming language Delphi Pascal supports the above mentioned I/O-functionality.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Peter18
Posts: 102
Joined: Thu May 12, 2011 1:01 pm

Re: Copying some Doc into an other one

Post by Peter18 »

Hello Villeroy, hello rudolfo,

thank you for your answers.

I think I'll use the dispatcher. Storing temporarly in a file looks to me more like a work around than like good programming style. But if I can use it with a special URL without a tempfile, it would be ok.

I'm sorry, my answer is late, but I had some problems to get all objekts copied, but now it looks good.

Thank you end greetings from the north sea

Peter
OpenOffice 3.3; OpenOffice 4.1.1
User avatar
Hagar Delest
Moderator
Posts: 32657
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: [Solved] Copying some Doc into an other one

Post by Hagar Delest »

Note that if you want more elegant commands, you can use the following subroutine:

Code: Select all

sub subDispatch(sCommand as string)
dim oFrame as object, oDispatcher as object
oFrame = ThisComponent.CurrentController.Frame
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oDispatcher.executeDispatch(oFrame, ".uno:" & sCommand, "", 0, array())
end sub
Then to use the paste command for example, you have to use:
subDispatch("Paste")
It may be possible to have the same kind of routine when an array of arguments is needed but not sure it's worth doing since the list of arguments can be long.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: Copying some Doc into an other one

Post by rudolfo »

Peter18 wrote:Storing temporarly in a file looks to me more like a work around than like good programming style.
I wonder who is teaching this. Just as an quick example: this forum running on phpBB will probably create thousands of temporary files in one day. PHP's session handling works with files in a temporary directory. The crucial point is to do it the right way, with proper file locking, serialization, unique file names and sensible permissions.
Basic is not able to fulfill this, but if you are working with a "real" programming language temporary files are often a solid solution.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Post Reply