[Solved] Copying cell values from remote files using macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
zwora
Posts: 35
Joined: Sun Oct 07, 2018 8:21 am

[Solved] Copying cell values from remote files using macro

Post by zwora »

Hi,

I've got file A in which by a macro I open another file (B) to get some data from there. It works fine until I try to copy cells with formulae inside. I would like to copy the value of the formula instead of formula. To open file B I use loadComponentFromURL() function.

Thank you
Last edited by robleyd on Mon Oct 22, 2018 10:50 am, edited 1 time in total.
Reason: Tagged [Solved] [robleyd, Moderator]
Windows 7/Windows 10, Open Office 4.1.2
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Copying values of cells from remotely open files using m

Post by Zizi64 »

The normal Copy/Paste functions will copy all of the cell contents (value, string and formula) and the formatting properties.

use the paste special function with the macro recorder, or write your macro based on the API functions. You can get the Value only from the source cell with the API functions, and you can put it into the target cell.
API: Application Programming Interface.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
zwora
Posts: 35
Joined: Sun Oct 07, 2018 8:21 am

Re: Copying values of cells from remotely open files using m

Post by zwora »

Ok. I am using OO Basic and copy using the following code:

Code: Select all

oDoc1.CurrentController.Select(oRange1)
oDispatcher.executeDispatch(oFrame1, ".uno:Copy", "", 0, aOpenProperties())
oDoc2.CurrentController.Select(oRange2)
oFrame2 = oDoc2.CurrentController.Frame
oDispatcher.executeDispatch(oFrame2, ".uno:InsertContents", "", 0, aOpenProperties())
What should I change in my code to get value instead of the formula? Maybe there is some evaluating function or cast-like operator?
Windows 7/Windows 10, Open Office 4.1.2
zwora
Posts: 35
Joined: Sun Oct 07, 2018 8:21 am

Re: Copying values of cells from remotely open files using m

Post by zwora »

I was trying with uno:PasteSpecial and it was almost ok (just the Paste Special dialog appears), but the solution is much easier. I just did it as i was copying ranges in the same document and that works:

oRange1.setDataArray(oRange2.getDataArray)

where oRange1is in document A nad oRange2 is in document B.

But it works when I copy from B to A. In opposite direction (A to B) I need to use oDispatcher.executeDispatch()
Windows 7/Windows 10, Open Office 4.1.2
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Copying values of cells from remotely open files using m

Post by Zizi64 »

But it works when I copy from B to A. In opposite direction (A to B) I need to use oDispatcher.executeDispatch()
Please upload your macro code and two ODF type sample file here.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
zwora
Posts: 35
Joined: Sun Oct 07, 2018 8:21 am

Re: Copying values of cells from remotely open files using m

Post by zwora »

The solution I used works fine for me, so my problem is solved. I should to put [Solved] in the topic of first post, but the topic content is too long to add anything there. Now I am chasing through other problems (described in other threads) however I consider OO Calc as the amazingly powerful tool with almost unconfined possibilities. The only problem is to know, hot to properly use it.
Windows 7/Windows 10, Open Office 4.1.2
Post Reply