Page 1 of 1

Select Whole Writer Document

Posted: Sun Feb 03, 2019 9:49 pm
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