I wan't to export a Jasper Report to Pdf & Excel.
When the export type is PDF : i need the pagination of document to
be ignored.
When the type id EXcel : i need even page on an excel sheet and rename these sheet's by the label of the un-repeated group.
To print the whole document in a single page, your report must ignore pagination by default. For this, you've to check ignore pagination to true.
Your_Report >> Properties >> ignore pagination = true
For excel sheet's, add the following variable in a field that changes for each group, it makes it possible to do the jump for a new sheet.
<property name="net.sf.jasperreports.export.xls.break.after.row" value="true"/>
For change the name of the sheet dynamically on excel, you can use :
<propertyExpression name="net.sf.jasperreports.export.xls.sheet.name"><![CDATA[$F{libUniteOrg}]]></propertyExpression>
Related
We are using JasperReports 6.0.0 and have about 30 templates for different reports that have almost nothing in common. Today we have got a requirement to print application version at the bottom of each page for every report.
I could not find any good solution to do it without modifying every template file. Does JasperReport allows to specify general layout for all templates? Is there any solution to add label to each page without modifying existent templates?
Some approaches:
Modify all .jrxml files and add a footer to each one, manually.
Use XSLT to modify all the .jrxml templates and add a footer.
Use iText to modify the report output after generating the report PDF.
Use the JasperReports API to programmatically inject a footer band into the in-memory template prior to compilation and execution.
Use the JasperReports API to programmatically inject a footer band into each .jrxml file and save the file back to disk.
Create a master template and include a parameterized subreport.
The last approach would have a master template as follows:
-----------
| Title |
-----------
| Subreport |
-----------
| Footer |
-----------
Then, when running the report, pass in a parameter that indicates what subreport to include (i.e., one of thirty). In this fashion, the Title Band and Footer Band are shared by all thirty reports. It's more work, but ultimately the most flexible solution.
If the Title Band differs completely across all reports, parameterize it to use a subreport.
Here's a screenshot of a master report that includes a subreport, which is given as a parameter. In the screenshot, the Title Band doesn't include a subreport because each of the several reports looks identical (the human-readable report title is also a parameter). It should be easy to see that if the Title Band had to change its layout for each report, then using a subreport instead would facilitate such a solution:
The footer, though, as shown in the screenshot, is one possible answer to your question.
You may need to define a variable that allows for calculating the page numbers:
<variable name="V_CURRENT_PAGE_NUMBER" class="java.lang.Integer" resetType="Page">
<variableExpression><![CDATA[1]]></variableExpression>
<initialValueExpression><![CDATA[$V{PAGE_NUMBER}+1]]></initialValueExpression>
</variable>
And a corresponding text field that references the page number:
msg("Page {0} of {1}", $V{V_CURRENT_PAGE_NUMBER}, $V{PAGE_NUMBER})
Keeping in mind that JasperReports uses absolute paths, define a few parameters to avoid hard-coding the location of the subreports. For example:
$P{P_REPORT_SUBREPORTS_PATH} + $P{P_SUBREPORT_NAME} + ".jasper"
Here, P_REPORT_SUBREPORTS_PATH is defined in terms of a P_REPORT_BASE variable:
$P{P_REPORT_BASE} + "subreports/"
This allows the report IDE to use a different directory than that of the web server by providing a different value for P_REPORT_BASE, depending on context.
Finally, keep in mind that what might be seemingly different reports could be a parameterized report. JasperReports allows for custom styles, which makes possible to dynamically change the report appearance (e.g., text justification, fonts, emphasis, borders, and so forth). In the screenshot, the report title, for example, is changed with each of the several reports--but they all share the same Title Band because the report title is passed in as a String parameter.
I have a problem with exporting rpt file to excel,
My requirement is to:
Display page numbers when printing from a Crystal Report (rpt) file and
Suppress the page number when exporting this to excel,
I am having trouble with the suppression and need help.
One way you can achieved by creating a static parameter as ExportFormat and put two value as 'default' and another one 'excel'..
Then add this parameter to your report with any string field notequalto the parameter..
finally in the PageNumber field in the suppress put this formula
if {?ExportFormat} = 'excel' then true else false
When ever user want to export to excel select "excel" if user want to view in crystal or any other export format select default..So that page number will suppress only when user select export format as 'excel'...
Context
Setup: JasperReports server Product Version: 6.0.1 Build: 20141218_0238, CentOS server. I am using their bundled PostgreSQL + tomcat server setup.
In my report i have a table with text field and static field & and a chart in the summary band.
the static fields are in columnHeader band, and text fields are in the detail band.
I require the table because i want the users to be able to export CSV data.
However when the report is viewed as HTML, i want to exclude the two bands mentioned above (detail/columnHeader).
Problem
I am able to exclude the table so that it's not showed using the following:
net.sf.jasperreports.export.html.exclude.origin.band.1=detail
net.sf.jasperreports.export.html.exclude.origin.band.2=columnHeader
This does hide the two bands mentioned above, however now instead of the data - whitespace is shown, i would to know how i can remove it
The red text above was added by me, as you can see there are unwanted white-space between the title and the chart, that was where the columnHeader and detail band were at.
See the JRXML content.
Question
How can I remove the space?
It could be an issue with your styles or theme. I run the report in Jasper studio and there was no white space, but I created dummy styles (table_heading, table_data) and set the default theme for bar chart.
Here is my report
http://pastebin.com/fnAnvBR1
I'm using JasperStudio 5.6.2
Set the following property to true:
net.sf.jasperreports.export.html.remove.empty.space.between.rows
Earlier versions of JasperReports had a typo, for the property (emtpy instead of empty):
net.sf.jasperreports.export.html.remove.emtpy.space.between.rows
For example:
<property name="net.sf.jasperreports.export.html.remove.emtpy.space.between.rows" value="true"/>
<property name="net.sf.jasperreports.export.html.remove.empty.space.between.rows" value="true"/>
I'm creating a jasper report using iReports 5.2.0 and I want to display the report file name in it.
Can't find any variable that has that information and I would like to get an alternative to pass it in the parameters.
How can I do it?
When you design your report, make a new PARAMETER named, for instance: NAME_REPORT.
After that, put a TextField in your report, for example, in your Title section, and
put as value of your TextField the parameter like a expression: $P{NAME_REPORT}
When you preview your report, ask you to give a value to this parameter and then, you see the title with the name
of your report file.
In your java code you will do somethink like that:
parameters.put("NAME_REPORT", "myreport.jrxml");
.....
JasperFillManager.fillReport(report, parameters, connection)
.....
Trying to export a report to excel, the generated document has kind of page break. The column header is repeated. The "page break" are in the same positition than if I generate a PDF report.
How can I remove this page break when exporting to excel? Is there some page size definition?
Have you tried ExportFormatType.ExcelRecord instead of ExportFormatType.Excel? The xls file will be created without formatting.
If actually the user is exporting report using ReportViewer Toolbar Export button you can:
Replace the CrystalReportViewer Control with the ReportExporter Control. It will export the report in the format you choose.
Or hide Export button from toolbar and put in the page buttons that exports programmatically
Call ExportToHttpResponse method
CrystalReportSource1.ReportDocument.ExportToHttpResponse(ExportFormatType.ExcelRecord, this.Response , false, "report.xls");
Call ExportToDisk method
reportDocument.ExportToDisk(ExportFormatType.ExcelRecord, "report.xls");
Export dataset to excel (Look at Ahmed answer)
You can choose the way that best fits your needs, but you must try if it works with the runtime you use either in development or in release server.
ExportFormatType.ExcelRecord means that is generated an xls file, without formatting. If you set ExportFormatType.Excel fields that are marked as "Can Grow" are merged with an otherwise blank row below them.