[Solved] Delete Columns Macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Nocton
Volunteer
Posts: 533
Joined: Fri Nov 05, 2010 10:27 am
Location: UK

[Solved] Delete Columns Macro

Post by Nocton »

After doing some calculations I want to clean up the spreadsheet by deleting some columns (I:L) automatically. So I recorded what I want to do and got:

Code: Select all

sub ClearCol
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:DeleteColumns", "", 0, Array())

end sub
As can be seen, the recorder has not recorded the columns to delete and a when it runs it deletes the whole spreadsheet.

What do I need to add to indicate the columns to delete?
Last edited by MrProgrammer on Thu Aug 01, 2019 8:33 pm, edited 3 times in total.
Reason: Moved from Calc forum to OpenOffice Basic, Python, BeanShell, JavaScript
OpenOffice 4.1.12 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Delete Columns Macro

Post by Villeroy »

Code: Select all

sub delete_IL()
	sh = ThisComponent.CurrentController.getActiveSheet()
	
	' mri = createUnoService("mytools.Mri")
	' mri.inspect(sh)
	
	addr = sh.getRangeAddress()
	addr.StartColumn = 8
	addr.EndColumn = 11
	sh.removeRange(addr, com.sun.star.sheet.CellDeleteMode.COLUMNS)
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
Nocton
Volunteer
Posts: 533
Joined: Fri Nov 05, 2010 10:27 am
Location: UK

Re: Delete Columns Macro

Post by Nocton »

Many thanks, Villeroy. That worked perfectly.
OpenOffice 4.1.12 on Windows 10
Post Reply