How to place text on blank page?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
tommydog
Posts: 19
Joined: Wed Jan 13, 2021 2:24 am

How to place text on blank page?

Post by tommydog »

I am using the below macro to produce automatic numbering on every line in writer. I have a document of blank pages that I wish to apply this numbering to, but the problem is when I run the macro, it does not write the numbering to the existing blank pages, but writes to new pages at the end of the document. How can I write to the existing blank pages?

attached is a sample of the blank pages that I wish to write to (various sizes and orientation). I need a quick way to do this, as in practice I will have hundreds of blank pages that need to have the numbering applied, and the order,orientation, size of these blank pages must be preserved.


Macro I am using:

Code: Select all

Sub Main

    Dim i As long

    Do 
        i = inputbox("How many lines you require?","Line Count")

    loop While not isNumeric(i)


    Dim oText
    oText = ThisComponent.Text

    Dim n   

    For n = 50 To i
        oText.insertString(oText.getEnd(), CHR$(13) & n & CHR$(9) , false)
    Next n

    Print "Done!"
End Sub
Attachments
blank pages.odt
(4.69 KiB) Downloaded 256 times
OpenOffice 4.1.8 on Windows 10
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: How to place text on blank page?

Post by RoryOF »

I think the alterations you need for the macro are discussed on this page
https://wiki.openoffice.org/wiki/Writer/API/TextRange
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
tommydog
Posts: 19
Joined: Wed Jan 13, 2021 2:24 am

Re: How to place text on blank page?

Post by tommydog »

RoryOF wrote:I think the alterations you need for the macro are discussed on this page
https://wiki.openoffice.org/wiki/Writer/API/TextRange
Thanks for your reply, however the only thing I can deduce from that is that the insertString parameter may have to be changed. I did not write the macro and know nothing about scripting, so if anyone could tell me what to change in the macro to achieve what I want to do then I would be very grateful.
OpenOffice 4.1.8 on Windows 10
User avatar
keme
Volunteer
Posts: 3704
Joined: Wed Nov 28, 2007 10:27 am
Location: Egersund, Norway

Re: How to place text on blank page?

Post by keme »

I don't know how to fix the macro, but do you need the numbering inserted as part of file content?

If it is for visual purpose, the automatic line numbering may be what you are after.
Menu item Tools - Line Numbering..., tick Show numbering and set interval to 1.

If you don't need the numbering everywhere, you can enable it per paragraph. For that, it is often a good idea to use different paragraph styles and make the setting in the style.

I may be out of line and stating the obvious here. No offense intended. Just thought it worth mentioning.
 Edit: I somehow missed the "blank pages" part. To have the kind of numbering I suggested on blank pages, lines must be inserted, either as newline (shift+enter) or new paragraph (enter). This is a bad idea if the doc is to be subsequently edited. Sorry if I muddied the subject. 
Post Reply