[SOLVED] Copy range from an already opened document

Creating a macro - Writing a Script - Using the API

[SOLVED] Copy range from an already opened document

Postby patel » Fri Jun 19, 2020 10:53 am

Hi all, I don't want load an existing document but access to an already opened document
Last edited by robleyd on Sat Jun 20, 2020 1:36 am, edited 3 times in total.
Reason: Add green tick
OpenOffice 4.1 on Windows 10
LibreOffice 5.2 on Windows 10
patel
 
Posts: 36
Joined: Tue Jun 19, 2012 2:48 pm

Re: Copy range from an already opened document

Postby Villeroy » Fri Jun 19, 2020 11:11 am

loadComponentFromURL returns the document no matter if it was already loaded or not.
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: 28441
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Copy range from an already opened document

Postby patel » Fri Jun 19, 2020 11:32 am

But it opens another istance of document, there is no way with getFrames() ?
OpenOffice 4.1 on Windows 10
LibreOffice 5.2 on Windows 10
patel
 
Posts: 36
Joined: Tue Jun 19, 2012 2:48 pm

Re: Copy range from an already opened document

Postby Villeroy » Fri Jun 19, 2020 12:22 pm

doc = StarDesktop.loadComponentFromURL( strURL, "_default", 0, Array())

of course you can loop through the frames but this is not necessary.
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: 28441
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Copy range from an already opened document

Postby patel » Fri Jun 19, 2020 8:49 pm

Thank You ! It runs.
Can you show me how to solve with Getframes ?
OpenOffice 4.1 on Windows 10
LibreOffice 5.2 on Windows 10
patel
 
Posts: 36
Joined: Tue Jun 19, 2012 2:48 pm

Re: [SOLVED]Copy range from an already opened document

Postby JeJe » Fri Jun 19, 2020 9:13 pm

Code: Select all   Expand viewCollapse view

   vFrames = StarDesktop.getFrames()
   For i = 0 To vFrames.getCount()-1
   vframe = vFrames.getByIndex(i)
      if vframe.controller.model.supportsservice ("com.sun.star.text.TextDocument") then 'for a text doc
'do whatever
      end if
   next
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 1089
Joined: Wed Mar 09, 2016 2:40 pm

Re: [SOLVED] Copy range from an already opened document

Postby Villeroy » Sat Jun 20, 2020 2:34 pm

Code: Select all   Expand viewCollapse view
eDocs = StarDesktop.Components.createEnumeration()
while eDocs.hasMoreElements()
  oDoc = eDocs.nextElement()
  if oDoc.supportsservice ("com.sun.star.text.TextDocument") then
    msgbox "Gotcha, "& oDoc.getURL()
  endif
wend

btw, we do not know all that shit by heart. We simply look it up with viewtopic.php?f=74&t=49294
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: 28441
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [SOLVED] Copy range from an already opened document

Postby JeJe » Sat Jun 20, 2020 2:55 pm

Note: if you have more than one window open for a document then you get the controller for each frame by enumerating the frames. If you enumerate the components instead then you don't. If you've just got one window open this doesn't matter.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 1089
Joined: Wed Mar 09, 2016 2:40 pm

Re: [SOLVED] Copy range from an already opened document

Postby patel » Mon Jun 22, 2020 6:39 am

Thanks again
OpenOffice 4.1 on Windows 10
LibreOffice 5.2 on Windows 10
patel
 
Posts: 36
Joined: Tue Jun 19, 2012 2:48 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests