[Solved] PasteCellRange

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
RichieRH
Posts: 36
Joined: Sun Oct 19, 2014 6:16 pm

[Solved] PasteCellRange

Post by RichieRH »

Hello , I m a newbie using macro AOO. I m having trouble to find the solution of my script . I just wanna paste data from a cell in another sheet using the "pastecellRange".Help me to solve and fix my script please.....many tks

Code: Select all

sub copas

dim copy as object
dim doc as object
dim tim as object
dim paste as object
dim osheet as object
dim t as boolean 
dim u as boolean 
dim v as boolean 

t= False
u= false
v= false 

doc=thiscomponent
osheet=doc.sheets.getbyname ("Sheet2")
copy=osheet.getcellrangebyname ("a1:b1")
tim=thiscomponent.currentcontroller
paste=doc.sheets.getbyname ("Sheet1").getcellrangebyname ("a3:b3")

tim.PasteCellRange(paste,com.sun.star.sheet.PasteOperation.ADD,copy,t,u,v,com.sun.star.sheet.CellInsertMode.DOWN)

end sub
Last edited by Hagar Delest on Sat Nov 01, 2014 5:13 pm, edited 1 time in total.
Reason: tagged solved
Debian 8 Jessie
Linux Mint 17.3 XFCE
Country : Indonesia
Learning is a need
FJCC
Moderator
Posts: 9549
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: PasteCellRange

Post by FJCC »

Try using copyRange() instead.

Code: Select all

doc=thiscomponent
osheet=doc.sheets.getbyname ("Sheet2")
copy=osheet.getcellrangebyname ("a1:b1")
copyRangeAddr = copy.RangeAddress
paste=doc.sheets.getbyname ("Sheet1").getcellrangebyname ("a3")
pasteCellAddr = paste.CellAddress
osheet.copyRange(pasteCellAddr, copyRangeAddr
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
RichieRH
Posts: 36
Joined: Sun Oct 19, 2014 6:16 pm

Re: PasteCellRange

Post by RichieRH »

Tks FJCC for your fast response..Sorry if my english is bad.. I know the use of the "CopyRange". But I want something else. Since I look the PasteCellRange, I wonder if this code can work either.
I want the data can be pasted in other cell and make the existing data (example : the data in sheet1.a3:b3) will move down (like Insert down cell)after the new data has been pasted ,but not make the existing cell in the right side (example:sheet1.c3:g3) is moving down either.

I m curious of what is the functions of the "PasteCellRange" :-)
Debian 8 Jessie
Linux Mint 17.3 XFCE
Country : Indonesia
Learning is a need
FJCC
Moderator
Posts: 9549
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: PasteCellRange

Post by FJCC »

Since PasteCellRange() is deprecated and I can't find where it is available, I tried using insertCells() followed by copyrange(). Does this work?

Code: Select all

doc=thiscomponent
osheet=doc.sheets.getbyname ("Sheet2")
copy=osheet.getcellrangebyname ("a1:b1")
copyRangeAddr = copy.RangeAddress
oPasteSheet = doc.sheets.getByName("Sheet1")
pasteRng= oPasteSheet.getcellrangebyname ("a3:b3")
oPasteSheet.insertCells(pasteRng.RangeAddress, com.sun.star.sheet.CellInsertMode.DOWN)
pasteTarg = oPasteSheet.getcellrangebyname ("a3")
osheet.copyRange(pasteTarg.CellAddress, copyRangeAddr)
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
kingfisher
Volunteer
Posts: 2127
Joined: Tue Nov 20, 2007 10:53 am

Re: PasteCellRange

Post by kingfisher »

The methods getDataArray and setDataArray are an alternative.
Apache OpenOffice 4.1.12 on Linux
User avatar
RichieRH
Posts: 36
Joined: Sun Oct 19, 2014 6:16 pm

Re: PasteCellRange

Post by RichieRH »

Thanks again for your help FJCC..
Yeah it does work very nice......Well, I ll use your script to finished my project.

For Kingfisher > Any script for the alternative using "SetDataArray" & "GetDataArray" would be appreciate??

Because I just wanna know what is the best code and easy to understand for me. In fact , I don't know how to write script in BASIC (AOO) til now. I only read in the forum and google search to know the usage of any script that I need to make my project . Of course, I know how to placed the code and put the macro into the buttons. So I Seek for the best and most suitable code then I try and error to have the results.

I heard about MRI tools, but I don't know how to use it?Where should I learned from?Especially for the beginner like me? I know that this is not the right post to ask it...But any link would be very helpful ???
Debian 8 Jessie
Linux Mint 17.3 XFCE
Country : Indonesia
Learning is a need
User avatar
kingfisher
Volunteer
Posts: 2127
Joined: Tue Nov 20, 2007 10:53 am

Re: PasteCellRange

Post by kingfisher »

The following thread would be a good place to start for Basic. If you download Andrew Pitonyak's macro document I suggest you download the pdf version. Thread : Basic Documentation.

Other code languages are supported, such as Python : Python and OpenOffice.
Apache OpenOffice 4.1.12 on Linux
User avatar
RichieRH
Posts: 36
Joined: Sun Oct 19, 2014 6:16 pm

Re: PasteCellRange

Post by RichieRH »

Tks Kingfisher for your help to show me the link, I also have been download the Andrew Pitonyak Files ..

Well.. I Consider this post is Solved ......
Debian 8 Jessie
Linux Mint 17.3 XFCE
Country : Indonesia
Learning is a need
Post Reply