Select Whole Writer Document

Creating Extension - 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 forum is not for asking questions about writing your own macros.

Select Whole Writer Document

Postby JeJe » Sun Feb 03, 2019 9:49 pm

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   Expand viewCollapse view
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
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 385
Joined: Wed Mar 09, 2016 2:40 pm

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 0 guests