Select Whole Writer Document

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Select Whole Writer Document

Post by JeJe »

There is a problem with a table at the start of the document - its necessary to add a paragraph if so.

see viewtopic.php?f=7&t=59825

Code: Select all

sub test()
	dim AddedParaAtStart as boolean
	SelectWholeWriterDocument(thiscomponent,AddedParaAtStart)
	msgbox AddedParaAtStart
end sub

Sub SelectWholeWriterDocument(Doc,byref AddedParaAtStart as boolean)
	dim dispatcher as object,OVC
	oText= doc.text
	OVC =thiscomponent.currentcontroller.viewcursor ' oText.createTextCursorByRange(oText.getStart)
	with oVC
		.JumpToFirstPage(false)
		.JumpToStartOfPage(false)
		do until res = false
			res =.goUp(1,false)
		loop
		if Not IsEmpty(.TextTable) then 'if table at start then need to insertparagraph
			'see https://forum.openoffice.org/en/forum/viewtopic.php?f=7&t=59825
			'Text.insertControlCharacter(oVC,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false) DOESN'T DO THIS
			dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
			dispatcher.executeDispatch(Doc.CurrentController.Frame, ".uno:InsertPara", "", 0, Array())
			AddedParaAtStart = true
		end if
		.gotoend(true)
	end with
End Sub


Edit:fixed calling name of sub in Test function
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply