Copy a cell to clipboard

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
oonk
Posts: 23
Joined: Fri Oct 04, 2019 8:03 am
Location: Pathum Thani, THAILAND

Copy a cell to clipboard

Post by oonk »

Code: Select all

Option Explicit
Sub CopyAndPaste1
	Dim sSource As Object : sSource = ThisComponent.CurrentController.Selection.getRangeAddress()
        Dim dDestination As Object : dDestination = ThisComponent.CurrentController.ActiveSheet.getCellByPosition(4,0).getCellAddress()
       ThisComponent.CurrentController.ActiveSheet.copyRange(dDestination, sSource)
End Sub

Sub copy_range_and_paste_it_to_another_cell
'Based on >> https://forum.openoffice.org/en/forum/viewtopic.php?f=25&t=16413#p160853
	Dim oSheet1 	As Object	: oSheet1 		= thisComponent.Sheets.getByIndex(0)
	Dim oSheet2 	As Object	: oSheet2 		= thisComponent.Sheets.getByIndex(1)
	Dim source 		As Object	: source 		= oSheet1.getCellRangeByName("A1:B3").getRangeAddress()
	Dim destination As Object 	: destination 	= oSheet2.getCellByPosition(0,0).getCellAddress()
	oSheet1.copyRange( destination , source )
End sub
After running Sub copy_range_and_paste_it_to_another_cell, I could paste in the other cell(s) manually.
How can Sub CopyAndPaste1 remain source cell's content in memory after copy and paste a cell ?
I would like to paste it in the other cell(s) manually.
Last edited by oonk on Sun Dec 08, 2019 5:40 pm, edited 1 time in total.
| Fedora 31 Workstation Cinnamon of Fedora from Spins | LibreOffice 6.2.8.2-2 | Base with embedded Firebird |
User avatar
Zizi64
Volunteer
Posts: 11362
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Remain cell's content in memory after Copy and Paste a c

Post by Zizi64 »

Then you must use the Windows clipboard. Search for sample code in Andrew Pitonyak's free macro books.
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.
oonk
Posts: 23
Joined: Fri Oct 04, 2019 8:03 am
Location: Pathum Thani, THAILAND

Re: Remain cell's content in memory after Copy and Paste a c

Post by oonk »

Zizi64 wrote:Then you must use the Windows clipboard. Search for sample code in Andrew Pitonyak's free macro books.
Thank you so much for your advice.

Code: Select all

Option Explicit
Sub CopyACellToClipboard()
	Dim oRange, oDisp, octl, NoArg()
	REM Set source doc/currentController/frame/sheet/range.
	octl 	= ThisComponent.getCurrentController()
	oRange 	= octl.Selection.getCellAddress()
	REM Create the DispatcherService
	oDisp	= createUnoService("com.sun.star.frame.DispatchHelper")
	REM Select source range
	octl.Select(oRange)
	REM Copy the current selection to the clipboard.
	oDisp.executeDispatch(octl, ".uno:Copy", "", 0, NoArg()) 
End Sub
It also sends the ASCII character code 13, how can I delete such CR ?
Attachments
Screenshot_20191208_222020.jpg
| Fedora 31 Workstation Cinnamon of Fedora from Spins | LibreOffice 6.2.8.2-2 | Base with embedded Firebird |
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Copy a cell to clipboard

Post by JeJe »

Get the cell's string content and use this:

viewtopic.php?f=21&t=93562
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply