Libreoffice base report grouping and Page N of M

Should be nice to know why that it’s necessary. Are those page numbers pointed anywhere? I guess not, if they are produced in the report. And such amount of pages I suppose are not printed on paper. If in a PDF, the tools in pdfs readers should help enough for any kind of search.

Will have a look if this could solved by a macro …

A ray of hope from your side. I am waiting for your code and how to implement it (complete steps). Thanks in advance.

There are around 4000 schools in our state and every month, we have to produce a report which contains around 500 pages every month for them. In this 500 page report there are roughly 200 schools so, some school report expands in 3 pages and if we gives something like Page 220 of 505, then it create confusion. So, it will be better if it have Page 1 of 3, Page 2 of 3 for that school.

Have had a look: It will be possible to change the table for the Group Header to set the number for the page to ‘1’, but I don’t find a way to set counter for the whole pages also.

So it would like
Page 1, Page 2, Page 1, Page 2, Page 3 …

Have read you are using this for schools. Don’t you need separate document for each school?

Yes, it will also work. I don’t need separate report because I generates PDF and then it sends by mail to our printing department.

Fast solution:

SUB GroupNewPage
	DIM oTables AS OBJECT
	DIM oTable AS OBJECT
	DIM inT AS INTEGER
	oReport = ThisComponent
	oTables = oReport.getTextTables()
	FOR inT = 0 TO oTables.count() - 1
		oTable = oTables.getByIndex(inT)
		IF Left$(oTable.name, 11) = "Gruppenkopf" THEN		
			oTable.PageNumberOffset = 1
		ENDIF
	NEXT inT
END SUB

Have a look at the name of the group header. In my German version it is named as “Gruppenkopf” in properties of the header in the report. This group should be set to pagebreak before.

Copy the code in your own macros, not in database.
Change the name of table. Be sure to set the the length of the word also (IF Left$(oTable.name, 11) = "Gruppenkopf" THEN)
Execute the report, start the macro.
Pagenumber will restart for every new group to 1.

If you start the report by macro from base, oReport will be the object you have startet. So the code could be added to the code for starting the report.

1 Like

Thanks again for your help. But, I am not getting where and how the name of group is going to affect in this code please? My table name is “LETFILE.dbf” which is a dbase table stored in /home/girish/fpd26. I have written the :

IF Left$(oTable.name, 7) = "LETFILE" THEN

Am I missing something at macro level, because this is my first base report so I am not aware how and when to run the macro with report before/after, so please elaborate complete steps.

Name of the group header you could find (and set) here:


If you execute the report you could see the name of the group header as name of the first table

So: Open the report for editing.
Click on the group.
See general properties.
Set the name as you want.
You have set Force New Page → Before Section if you want a new page for every member of the group.

I have placed SCH (name of the field of table which have school code) two times because I have to print the header (because repeat section YES do not works, as it is a bug in base report software which have mentioned somewhere on internet) on every group i.e. if a particular school’s data expands more than 1 page, on consecutive pages, there should be school header. So, I have placed the same group header, in the first header i have set :
Name : LETFILE1
Force New Page : None
Keep Together : No
Repeat Section : No
Visible : No
Height : 0.03 cm

In the next same header which is based on SCH field
Name : LETFILE
Force New Page : Before Section
Keep Together : No
Repeat Section : Yes
Visible : No
Height : 12.57 cm

But, I am not able to see the Page Number 1 for next school letter.

Please make a screenshot of your design. If you set the pagebreak to “Before Section” and let the section be repeated, this will always be “1” as page number.
You have to choose Insert → Page Numbers → Page N. This number will be reset every time the name of the table appears. So it should be a header, which appears only one time for every group.

Name : NewRow
Force New Page : Before Section
Keep Together : No
Repeat Section : No
Visible : Yes
Height : 0.03 cm

Why do you create a page header with height of 12.57 cm, which shouldn’t be visible?
Set the names different for the header with the break. So the macro could find it.
A simple example here. Open the form and press “Start Report” in the form.
Test.odb (19.4 KB)

Let me re-elaborate. I am preparing letters for schools in which there will be some rows. In this report, I have two groups on a same field SCH (which is school code). First group (LETFILE1) is not visible and the second one (LETFILE) in which I have placed our company name, address of school, few fixed lines in a lable. Why I have placed two groups because some where in launchpad, it has mentioned that its a bug and workaround is place two group and keep one invisible. Its my typo error that in my last message I said Visible : No for 12.57 cm header, actually its visible is YES, I am sorry for this mistake. As you said, Insert Page Number N, so yes, I have placed that control and it is not getting reset to 1.

One thing I noticed, when I opens your test.odb, it opens Libreoffice security warning for macros, but when I opens my database it do not shows this warning box.

Security warning appears, because it contains macros. The macro I have written is inside the Base document. So you have to allow executing macros.
Have tried a little bit with repeated Group Header. See attached new example. It’s looking a little bit confusing, but if you repeat the Group Header it will appear in the header of the page, not in content. So the Group Header for changing the page number must be set after the repeated header.
Test.odb (20.4 KB)
Allow to execute macros for this. You couldn’t start the report in the form without allowing this.

Check this link which says, if you wish to repeat the group header on each page :
https://bugs.documentfoundation.org/show_bug.cgi?id=82097#c12

That’s what I wrote there …

That’s great, its you there. Now, please send your test.odb for repeat header and Page Numbering. I don’t know why I am not able to reset page number to 1.

See the post with the second database 22 minutes ago.

Sorry, but it is showing continuous page numbers. It is not getting to reset on next town.

Did you really start the report through the macro? Open the form. Press the button. Report starts here and shows page 1 and 2 for “London”, page 1 up to 6 for “Rio” and page 1, 2 and 3 for “Tokio”.

Yes, now everything is fine as I closely viewed your .odb. Thank you very much Robert. I learnt many new things. My next topic is to preserve the value of Auto Grow Yes. Probably somewhere in this forum it has been discussed. Thanks once again for your help.