Ask Your Question
0

Writer: Sort document by paragraph

asked 2018-11-30 10:17:20 +0200

michaelof gravatar image

updated 2018-12-10 15:58:51 +0200

Hi all,

asked this question in German, longer ago, never got an answer. Let's try in English :-)

I've a longer Writer doc, some sort of FAQ, written and updated by me regularly. Heading "Heading 1" start always like "<topic>: ....", so it would be cool to get the whole doc sorted by these topics, by "Heading 1". Concretely: Each sort item should be a "Heading 1" paragraph and all other subsequent paragraphs, until the next "Heading 1" (or EOF, of course).

Based on what I've found, I strongly believe that there'e no existing LO Writer functionality doing this, the built in "Sort" command is greyed out if I try to mark the whole doc. And throws an error if marking some paragraphs only.

So I guess I must do this with some sort of (basic ?) macro, but to be honest I've no real clue where and how to start. Found several docs about functions, the API etc.. But no "beginners" guide, does anyone maybe have a small example of a macro "looping through a whole document, doing this and that", as a starting point?

Any hints appreciated!

Thanks in advance, Michael

As requested by JohnSUN: C:\fakepath\WissenswertesOpenSuseEtc.odt

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2018-11-30 10:32:09 +0200

JohnSUN gravatar image

updated 2018-11-30 10:32:43 +0200

Just run a macro named sortByHeader - C:\fakepath\Poems.odt

(It was first published on March 14, 2016 here)

edit flag offensive delete link more

Comments

Hi JohnSUN, thank you so much, for answering, and for your macro.

  • Tried to run your macro within the your document which contains the macro: runs fine, creates a new, sorted document.
  • Tried the same with my own document: Your macro starts, copies first heading and table of contents. Then macro stops with error (translated into English manually by me): "BASIC-Runtime error: Property or Method not found: ParaStyleName" in line 52:

    sParaStyleName = oParagraph.ParaStyleName

Any hints?

michaelof gravatar imagemichaelof ( 2018-12-05 17:42:34 +0200 )edit

Hmmm... Very strange. Michael, can you update your question and attach small example of your data?

JohnSUN gravatar imageJohnSUN ( 2018-12-05 19:36:33 +0200 )edit

Sure. It's not a secret doc and not big, so I try to upload it completely.

michaelof gravatar imagemichaelof ( 2018-12-10 15:57:48 +0200 )edit

Thank you. Problem was with text table in the question "LIBREOFFICE: „Datei neu“ in Dolphin". This macro was created to sort text strings only. Objects such as this table or the image in the "YAST: Nach Installation von Paketen im Modus..." question cannot be processed as plain text. You can try to improve the algorithm in this part, or simply pre-prepare the data for sorting: delete everything except the questions and answer texts, sort, return the result to the original document, paste the deleted objects in their places and recreate the table of contents.

JohnSUN gravatar imageJohnSUN ( 2018-12-10 18:37:33 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-11-30 10:17:20 +0200

Seen: 240 times

Last updated: Dec 10 '18