[Solved] [Calc] Delete Entire Row Content

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Gonzo714
Posts: 49
Joined: Wed Nov 23, 2016 2:52 pm

[Solved] [Calc] Delete Entire Row Content

Post by Gonzo714 »

I have the following macro to delete entire row(s) based on cell value of that specific row...

Code: Select all

Sub DeleteRows
oSheet=thiscomponent.getcurrentcontroller.activesheet
rem This routine assumes a single column range contains the values to be checked for row deletion
oRange = oSheet.GetCellRangeByName("N1:N118") 
oRows = ThisComponent.CurrentController.ActiveSheet.Rows
nStartRow = oRange.getRangeAddress.StartRow
nEndRow = oRange.getRangeAddress.EndRow
nCol = oRange.getRangeAddress.StartColumn
for nRow = nStartRow to nEndRow
rem The next line specifies the cell to be checked
oCell = oSheet.GetCellByPosition(nCol,nRow)
rem The next line specifies a value qualifying the row for deletion
if oCell.GetString = "delete this row" then 
Count = Count + 1
oRows.removeByIndex(nRow,1) 'the second argument limits deletion to 1 row at a time
End if
next
MsgBox Count & " rows deleted"
End Sub
I would like the macro to be altered to DELETE ROW CONTENT only.
I'm guessing this is the line that needs altered, but i'm unsure how..
oRows.removeByIndex(nRow,1)

Ive tried:
oRows.RemoveContent(nRow,1)
oRows.ClearContent(nRow,1)
Rows.ClearContent(nCells,1)
without success.
Any ideas / fast fixes??

..Im Debian 12 with LO 7.5.8
Last edited by Gonzo714 on Fri Dec 08, 2023 2:33 am, edited 1 time in total.
User avatar
Zizi64
Volunteer
Posts: 11476
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Delete Entire Row Content

Post by Zizi64 »

Code: Select all

Sub DeleteRowContent

	oSheet=thiscomponent.getcurrentcontroller.activesheet
	rem This routine assumes a single column range contains the values to be checked for row deletion
	oRange = oSheet.GetCellRangeByName("N1:N118") 
	oRows = ThisComponent.CurrentController.ActiveSheet.Rows
	nStartRow = oRange.getRangeAddress.StartRow
	nEndRow = oRange.getRangeAddress.EndRow
	nCol = oRange.getRangeAddress.StartColumn
	for nRow = nStartRow to nEndRow
		rem The next line specifies the cell to be checked
		oCell = oSheet.GetCellByPosition(nCol,nRow)
		rem The next line specifies a value qualifying the row for deletion
		if oCell.GetString = "delete this row" then 
			Count = Count + 1
			oRow = oRows.getByindex(nRow)
			'Xray oRow
			oRow.clearContents(1+2+4+8+16+32+64+128+256+512) 'https://www.debugpoint.com/deleting-all-types-of-contents-from-calc-range-using-macro/
			'oRows.removeByIndex(nRow,1) 'the second argument limits deletion to 1 row at a time
		End if
	next
	MsgBox "Content deleted from " & Count & " rows"
	
End Sub
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.
Gonzo714
Posts: 49
Joined: Wed Nov 23, 2016 2:52 pm

Re: Delete Entire Row Content

Post by Gonzo714 »

All hail the Gurus of OOF... :super:
appreciate it!
User avatar
Zizi64
Volunteer
Posts: 11476
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Delete Entire Row Content

Post by Zizi64 »

I Strongly suggest you to use an object inspection tool like the MRI or the Xray Tool. Then you will able to list the existing properties and methods of the programming objects.
And the google is your friend... I just Googled and Xrayed this solution.
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.
Post Reply