Page 1 of 1
[Solved] Copying some Doc into an other one
Posted: Wed Jan 25, 2012 2:22 pm
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
Re: Copying some Doc into an other one
Posted: Wed Jan 25, 2012 2:45 pm
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?
Re: Copying some Doc into an other one
Posted: Wed Jan 25, 2012 3:24 pm
by Peter18
Hallo Villeroy,
Villeroy wrote:Why don't you use the API then?
That's what I want to do!
Peter
Re: Copying some Doc into an other one
Posted: Wed Jan 25, 2012 3:46 pm
by Villeroy
Good choice.
Re: Copying some Doc into an other one
Posted: Wed Jan 25, 2012 3:52 pm
by Peter18
Hello Villeroy,
thank you, it was very helpfull!!!
Peter
Re: Copying some Doc into an other one
Posted: Wed Jan 25, 2012 6:22 pm
by Villeroy
Re: Copying some Doc into an other one
Posted: Wed Jan 25, 2012 7:55 pm
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
Re: Copying some Doc into an other one
Posted: Wed Jan 25, 2012 8:00 pm
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
Re: Copying some Doc into an other one
Posted: Thu Jan 26, 2012 12:20 am
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.
Re: Copying some Doc into an other one
Posted: Thu Jan 26, 2012 7:13 pm
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
Re: [Solved] Copying some Doc into an other one
Posted: Thu Jan 26, 2012 10:43 pm
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.
Re: Copying some Doc into an other one
Posted: Fri Jan 27, 2012 2:03 am
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.