[Solved] Copy Sheet to another sheet

Discuss the spreadsheet application
Post Reply
Rosinha
Posts: 6
Joined: Mon Jul 07, 2014 1:27 pm

[Solved] Copy Sheet to another sheet

Post by Rosinha »

Hello,

In OpenOffice Calc, I need to copy all the data present from one sheet to another sheet in the same document using Delphi.
Say For Example: In sheet1, I have loaded a template and now i try to copy the same template to sheet2.
Is there any way that i can copy the data from one sheet to another?
Last edited by Rosinha on Mon Feb 23, 2015 6:51 am, edited 3 times in total.
OpenOffice 4.0.1 on Windows XP
FJCC
Moderator
Posts: 9639
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Copy Sheet to another sheet

Post by FJCC »

Here is an example in Basic of copying the used area of Sheet 1 to Sheet2.

Code: Select all

oSheets = ThisComponent.Sheets
oSheet1 = oSheets.getByName("Sheet1")
oSheet2 = oSheets.getByName("Sheet2")

oCurs = oSheet1.createCursor()
oCurs.gotoStart()
oCurs.gotoEndOfUsedArea(True)
oRangeAddr = oCurs.RangeAddress

oTrgCell = oSheet2.getCellrangeByName("A1")
oCellAddr = oTrgCell.CellAddress

oSheet1.copyRange(oCellAddr, oRangeAddr)
Alternatively, you could just copy the sheet

Code: Select all

oSheets = ThisComponent.Sheets
oSheets.copyByName("Sheet1", "NewSheet", 1) 'put the sheet in position 1, which is second from the left
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.
jackrcook
Posts: 226
Joined: Sun May 25, 2014 11:08 pm

Re: Copy Sheet to another sheet

Post by jackrcook »

Sounds to me that all you need to do is click on the column/row intersection (upper left corner) of the sheet to copy then do an edit > copy and then open the second sheet and do an and edit > paste special. The paste special will allow you to keep all of the first sheet's formatting.

Hope this helps.
Open Office 4.1.13 ~on Mac OS 12.6
Rosinha
Posts: 6
Joined: Mon Jul 07, 2014 1:27 pm

Re: [Solved] Copy Sheet to another sheet

Post by Rosinha »

When using oSheets.copyByName("Sheet1", "NewSheet", 1) on windows 7/ windows 8 we get an error message " com.sun.star.uno.RuntimeException".
Are there any other alternatives for "copyByName" command?
OpenOffice 4.0.1 on Windows XP
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Copy Sheet to another sheet

Post by Villeroy »

Rosinha wrote:When using oSheets.copyByName("Sheet1", "NewSheet", 1) on windows 7/ windows 8 we get an error message " com.sun.star.uno.RuntimeException".
Are there any other alternatives for "copyByName" command?
Of course. This happens when there already is a sheet named "NewSheet".
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Rosinha
Posts: 6
Joined: Mon Jul 07, 2014 1:27 pm

Re: [Solved] Copy Sheet to another sheet

Post by Rosinha »

Villeroy wrote:
Rosinha wrote:When using oSheets.copyByName("Sheet1", "NewSheet", 1) on windows 7/ windows 8 we get an error message " com.sun.star.uno.RuntimeException".
Are there any other alternatives for "copyByName" command?
Of course. This happens when there already is a sheet named "NewSheet".

I am changing the "NewSheet" name everytime when i try to copy the sheet.In the above post i have mentioned for example purpose.
OpenOffice 4.0.1 on Windows XP
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Copy Sheet to another sheet

Post by Villeroy »

The macro simply works if there is a "Sheet1" but not any "NewSheet" and if the document is not protected.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Rosinha
Posts: 6
Joined: Mon Jul 07, 2014 1:27 pm

Re: [Solved] Copy Sheet to another sheet

Post by Rosinha »

Does CopyByName command supports on Windows 7 and windows 8?
OpenOffice 4.0.1 on Windows XP
FJCC
Moderator
Posts: 9639
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: [Solved] Copy Sheet to another sheet

Post by FJCC »

All of the macro functions should still work on Windows 7 and 8. CopyByName certainly works on Windows 7.
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.
Post Reply