Counting Track Changes

  • LibreOffice Version: 6.3.1.2 (x64)
  • Running on Windows 10

I’m searching for a way to count the number of changes made by an editor on a document. There is a macro that does this for Word, but it hasn’t been updated since 2015 and I’m not savvy enough with macros to be able to write one for LibreOffice.

The version for Word I found is here: Counting Inserted and Deleted Words in Track Changes – Translation Therapy

I’ve googled for a LibreOffice version and found nothing but that doesn’t mean it isn’t out there.

I tried copying the lines from the “Manage” window so I could paste them into a Calc document, but it won’t let me do that. I’m talking hundreds of changes so counting manually really isn’t an option. I just want a simple number of how many changes were tracked on a document. Does anyone know of a way I can do this?

Thank you!

Service for this exists: LibreOffice: RedlinePortion Service Reference

More late I try how…

I don’t know what a service is or how to implement it.

With this code, we get.

doc = XSCRIPTCONTEXT.getDocument()

i = 0
d = 0

for paragraph in doc.Text:
    is_change = False
    for part in paragraph:
        if is_change:
            is_change = False
            if part.String:
                if insert:
                    i += 1
                elif delete:
                    d += 1
            insert = False
            delete = False
            continue
        if part.TextPortionType == 'Redline':
            is_change = True
            if part.RedlineType == 'Insert':
                insert = True
            elif part.RedlineType == 'Delete':
                delete = True

msg = 'Insertions: {}\nDeletions: {}'.format(i, d)
print(msg)

image description

With Basic is little bit complicate, but possible.

I’m sorry, I don’t know how to get this to work. Can you walk me through the steps of using this please? I tried adding it as a macro, but honestly I don’t know what I’m doing. Thank you so much, this is exactly what I want, I just don’t know how to make it work. If you can break down exactly where to put it, I would be very grateful.

ok, try with Basic version, (Basic is boring)

Sub Main()
	doc = ThisComponent
	
	i = 0
	d = 0
	e1 = doc.Text.createEnumeration()
	Do While e1.hasMoreElements
		paragraph = e1.nextElement()
		e2 = paragraph.createEnumeration()
		Do While e2.hasMoreElements()
			part = e2.nextElement()
			If part.TextPortionType = "Redline" Then
				lineType = part.RedlineType
				If e2.hasMoreElements() Then
					part = e2.nextElement()
				End If
				If lineType = "Insert" Then
					i = i + 1
				ElseIf lineType = "Delete" Then
					d = d + 1
				End If		
				If e2.hasMoreElements() Then
					part = e2.nextElement()
				End If					
			End If
		Loop
	Loop
	
	message = "Insertions: " & i & Chr(13) & "Deletions: " & d
	MsgBox message
	
End Sub

Thank you so SO much! That works perfectly, and is just what I wanted. <3