Particularly posted for Librebel with thanks for his intent to help: Yes, Hubert Lambert has solved this persistent problem at the Apache Open Office Forum: Solved: Match Individual Macro API with the API index?
I have this example_txt.odt to show how I wish to use “Line Breaks” and “Paragraph Marks” to ease and automate the numbering of writing point-wise instruction steps. If I used Para mark somewhat differently in the text, I would have to manually engage in editing the document to suit my purpose.
Please refer to these posts:
Recall the following:
Paragraph character (`¶`): U+000D CR Carriage Return (0x0013) (entered at keyboard with `Enter` or `Return` key) Line-Break character (`↲`): U+000A LF Line Feed (0x00010) (entered at keyboard with `Shift+Enter` or `Shift+Return` key)
I want to build this macro:
- I will have two String variables declared within the macro.
- I use Find with Wild Characters to find out texts like
[a-z.A-Z.0-9]$. (These are usually the Title for the Paragraph.)
- For the first string my find encounters, I take this entire string into the string variable, including the
- I then count the length of the string. Suppose this is
- I now take (n-1)th ‘string-elements’ into consideration, and fill the second string with this truncated string and the
↲as the last element.
- I replace the first string with this second string.
- I do this from the top every time, till there are no other such entries I wish to replace.
Presently, I am able to replace such strings like
#####&, the & code is used to print the
##### after the text but before the
¶mark to help me identify such lines. These marks help me in manually editing the text.
How could I build this macro? I used the macro recorder, but can’t use the codes from within the macros for
): U+000D CR Carriage Return (0x0013) or
): U+000A LF Line Feed (0x00010)
Further Edited on 31/07/2017 at 1849Hrs (GMT+0530Hrs):
One problem still remains:
I learnt to understand your codes. Thank you for introducing me to StarBasic. Subsequently, I am in https://forum.openoffice.org. I partially modified the strings to be replaced:
rem Replace all Paragraph Breaks With Linefeeds Function Writer_ReplaceAll_Paragraph_Breaks_With_Linefeeds() As Long REM Replaces all Paragraph breaks with a Linefeed character within the current Writer document. REM Returns: the number of found/replaced occurrences. Dim oReplace as Object oReplace = ThisComponent.createReplaceDescriptor() oReplace.setSearchString( "[a-z,A-Z,0-9]$" ) oReplace.setReplaceString( "&" + chr(10) ) oReplace.SearchRegularExpression = True Writer_ReplaceAll_Paragraph_Breaks_With_Linefeeds = ThisComponent.replaceAll( oReplace ) End Function
Then I added another code to take care of the extra
¶mark after the
↲, because after running your modified code, I find that an extra empty para mark is left.
REM Reiteration to remove empty paras after above action Function Writer_ReplaceAll_Blank_Paras() As Long Dim bReplace as Object bReplace = ThisComponent.createReplaceDescriptor() bReplace.setSearchString( chr(10) + "^$" ) bReplace.setReplaceString( chr(10) ) bReplace.SearchRegularExpression = True Writer_ReplaceAll_Blank_Paras = ThisComponent.replaceAll( bReplace ) End Function
If I try to run this second code, I can’t find any result. Why? Where am I going wrong?
[Edited on 01/08/2017 in response to Librebel’s advice]
Perhaps you could use the following
macro for that: … …
oReplace.setSearchString( "$" )
But that line won’t serve my purpose. I am enclosing the three files, Test, Tested and WhatIWant
test.odt This is the original file to be edited.
tested.odt This is after running the first macro.
WhatIwant.odt This is what I really want.
I did try with
\n\n in the second macro, but it doesn’t work. Where am I going wrong?