Page 1 of 1

[Solved] [Calc] Delete Entire Row Content

Posted: Thu Dec 07, 2023 6:29 pm
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

Re: Delete Entire Row Content

Posted: Thu Dec 07, 2023 6:57 pm
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

Re: Delete Entire Row Content

Posted: Fri Dec 08, 2023 2:33 am
by Gonzo714
All hail the Gurus of OOF... :super:
appreciate it!

Re: Delete Entire Row Content

Posted: Fri Dec 08, 2023 8:21 am
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.