[Solved] Copying some Doc into an other one

Java, C++, C#, Delphi, ??? - Using the UNO bridges

[Solved] Copying some Doc into an other one

Postby Peter18 » Wed Jan 25, 2012 2:22 pm

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   Expand viewCollapse view
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
Peter18
 
Posts: 99
Joined: Thu May 12, 2011 1:01 pm

Re: Copying some Doc into an other one

Postby Villeroy » Wed Jan 25, 2012 2:45 pm

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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28544
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Copying some Doc into an other one

Postby Peter18 » Wed Jan 25, 2012 3:24 pm

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
Peter18
 
Posts: 99
Joined: Thu May 12, 2011 1:01 pm

Re: Copying some Doc into an other one

Postby Villeroy » Wed Jan 25, 2012 3:46 pm

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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28544
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Copying some Doc into an other one

Postby Peter18 » Wed Jan 25, 2012 3:52 pm

Hello Villeroy,

thank you, it was very helpfull!!!

Peter
OpenOffice 3.3; OpenOffice 4.1.1
Peter18
 
Posts: 99
Joined: Thu May 12, 2011 1:01 pm

Re: Copying some Doc into an other one

Postby Villeroy » Wed Jan 25, 2012 6:22 pm

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28544
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Copying some Doc into an other one

Postby Peter18 » Wed Jan 25, 2012 7:55 pm

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
Peter18
 
Posts: 99
Joined: Thu May 12, 2011 1:01 pm

Re: Copying some Doc into an other one

Postby Villeroy » Wed Jan 25, 2012 8:00 pm

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: viewtopic.php?f=20&t=35476&p=162730&hilit=transferable#p162730
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28544
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Copying some Doc into an other one

Postby rudolfo » Thu Jan 26, 2012 12:20 am

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.
rudolfo
Volunteer
 
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: Copying some Doc into an other one

Postby Peter18 » Thu Jan 26, 2012 7:13 pm

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
Peter18
 
Posts: 99
Joined: Thu May 12, 2011 1:01 pm

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

Postby Hagar Delest » Thu Jan 26, 2012 10:43 pm

Note that if you want more elegant commands, you can use the following subroutine:
Code: Select all   Expand viewCollapse view
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.
AOO 4.1.7 on Xubuntu 20.04 and 4.1.5 on Windows 10 (with winPenPack port).
User avatar
Hagar Delest
Moderator
 
Posts: 28951
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Copying some Doc into an other one

Postby rudolfo » Fri Jan 27, 2012 2:03 am

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.
rudolfo
Volunteer
 
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany


Return to External Programs

Who is online

Users browsing this forum: No registered users and 1 guest