Trouble porting from Excel to Open Office

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
TheCherub
Posts: 3
Joined: Sun Apr 20, 2008 3:12 pm

Trouble porting from Excel to Open Office

Post by TheCherub »

I have written a Macro in Excel for a friend of mine, which he now needs porting so that it works with Open Office (current version)

I have sorted most of the issues, such as the fact that OO uses ; instead of , as a argument separator, but I have one remaining problem.

Parts of the macro rely on copying and pasting data across the spreadsheet, and none of this is actually happening. The macro doesn't ever fall over or register that there is a problem, it just doesn't do these certain steps.

What is going on?
User avatar
squenson
Volunteer
Posts: 1885
Joined: Wed Jan 30, 2008 9:21 pm
Location: Lausanne, Switzerland

Re: Trouble porting from Excel to Open Office

Post by squenson »

I suggest you post the code so the experts in this forum can have a look.
LibreOffice 4.2.3.3. on Ubuntu 14.04
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Trouble porting from Excel to Open Office

Post by Villeroy »

Code: Select all

REM  *****  BASIC  *****

Sub test_copyRange
REM copy from 1st sheet B2:F5 to 2nd sheet A1
	copyRange oDoc:=thisComponent, nSh:=0, nStartCol:=1, nStartRow:=1, nEndCol:=5, nEndRow:=4, nTgtSh:=1, nTgtCol:=0, nTgtRow:=0
End Sub

Sub copyRange(oDoc, nSh, nStartCol, nStartRow, nEndCol, nEndRow ,nTgtSh, nTgtCol, nTgtRow)
Dim oSrc as new com.sun.star.table.CellRangeAddress
Dim oTgt as new com.sun.star.table.CellAddress
	oSh = oDoc.Sheets.getByIndex(nSh)
	oSrc.Sheet = nSh
	oSrc.StartColumn = nStartCol
	oSrc.StartRow = nStartRow
	oSrc.EndColumn = nEndCol
	oSrc.EndRow = nEndRow
	oTgt.Sheet = nTgtSh
	oTgt.Column = nTgtCol
	oTgt.Row = nTgtRow
	oSh.copyRange(oTgt, oSrc)
End Sub
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
TheCherub
Posts: 3
Joined: Sun Apr 20, 2008 3:12 pm

Re: Trouble porting from Excel to Open Office

Post by TheCherub »

Are you suggesting that you have to write a sub routine to copy and then paste to a range of cells?
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Trouble porting from Excel to Open Office

Post by Villeroy »

TheCherub wrote:Are you suggesting that you have to write a sub routine to copy and then paste to a range of cells?
Since you do not tell us anything, I wrote a subroutine which can be used to copy any range to any target cell within any spreadsheet document. I simply split up everything into the most tiny steps to make it as generic and plausible as possible. In the end it is nothing but a single call of method copyRange with a cell address and a range address. It's completely up to you to understand the concept and write something completely different. You could also leave it as is, copy sub test_copyRange and put the numbers you need. All the indices for sheets, columns and numbers are zero based.
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
TheCherub
Posts: 3
Joined: Sun Apr 20, 2008 3:12 pm

Re: Trouble porting from Excel to Open Office

Post by TheCherub »

Sorry, that reply of mine was uncalled for.

The person I am writing it for has now found himself a copy of Excel, so the issue has been sidestepped. Thank you to all who posted though.
Post Reply