You are not logged in.
Dear users of this forum,
we are pleased to inform you that we will be updating the software behind this forum in the near future.
Existing posts, users and categories will remain untouched.
Important:
We will keep you informed in the pinned thread.
Kind regards,
Your ReportServer Team
Liebe Nutzer dieses Forums,
wir freuen uns, euch mitteilen zu können, dass wir in naher Zukunft die Software hinter diesem Forum aktualisieren werden.
Existierende Beiträge, Nutzer und Kategorien bleiben weiterhin bestehen!
Wichtig:
Wir halten euch im angepinnten Beitrag auf dem Laufenden!
Mit vielen Grüßen
Euer ReportServer Team
Does reportserver script support page break events or page number?
I'd need to generate a report where the first line should be a recap of the previous page amount.
Ex:
page 1:
-------------------
A 5
B 3
C 2
-------------------
page 2:
-------------------
(reported) 10
D 6
E 13
F 9
-------------------
...
To do so, I'd need some an event or a page number to conditionaly output the 'reported' line
Rgds
Offline
Hi freds,
With script reports (almost) everything is possible.
What output formats do you need?
Karolina
Offline
PDF or text format (e.g. any format that would eventually be printed).
Offline
Hi,
See the example script below. It generates pdf with 5 data rows per page, with summaries at the top and at the bottom of the page.
import groovy.xml.MarkupBuilder
/* generate a dummy data set */
List data = []
def i = 0
('A'..'Z').each{key ->
i++
List rowData = []
rowData.add(key)
rowData.add(i)
data.add(rowData)
}
/* assume we want 5 rows per page */
int rowsPerPage = 5
int mod = data.size() % rowsPerPage
int numerOfPages
if(mod == 0){
numerOfPages = data.size() / rowsPerPage
} else {
numerOfPages = data.size() / rowsPerPage + 1
}
/* split the data set according to number of pages */
data = data.collate(numerOfPages)
/* the total number that will be displayed at the top and the bottom of each page */
def total = 0
/* render the page */
def writer = new StringWriter()
MarkupBuilder mkp = new MarkupBuilder(writer)
mkp.html{
head {
title ("My title")
style("""
@media print {
.summary {page-break-before: always;}
}
@page { size: A4 landscape;}
""")
}
body {
for(int j = 0; j < data.size(); j++) {
List subList = data[j]
def divClass
if(j == 0){
divClass = "firstPage"
} else {
divClass = "summary"
}
div("class":"${divClass}"){
/* summary row at the top of the page */
p("Summary from previous page(s): ${total}")
/* summarize numbers in sublist */
def subListSummary = 0
subList.each{row ->
subListSummary += row[1]
/* display rows */
p(row[0] + ": " + row[1])
}
/* add sublist summary to total number */
total += subListSummary
p("Summary for this page: ${subListSummary}")
p("Total: ${total}")
}
}
}
}
if(outputFormat == 'pdf'){
return renderer.get("pdf").render(writer.toString())
}
return renderer.get("html").render(writer.toString())You may further style the document using CSS, as if you created a HTML page for printing.
The tricky part may be to guess how many rows will fit the page.
When you need reports that ideally fit the printed page, other report engines may be better (Jasper or Birt)
Hope it helps
Karolina
Last edited by karolina (2017-01-05 12:49:49)
Offline
"The tricky part may be to guess how many rows will fit the page."
I would have expected the ReportServer engine to do that for me :[
Looks like script reports are limited to what HTML/CSS3 provides (e.g. very little)
Thanks for the detailled answer!
Last edited by freds (2017-01-05 13:33:28)
Offline
Well, you could probably calculate dynamically the value of rowsPerPage variable, if you know the printed page height in pixels (or the area on the page you'd like to reserve for data rows), font height in pixels (the one you want to use), margins, and data amount in characters.
Karolina
Offline