Jaspersoft subreport with source code - jasper-reports

I have my reports stored into a database as the source code. I need to then use this source code in my report as a subreport.
When I give the subreport expression the source code, it thinks it is a path to the file.
Is there a way to do this without needing to store the source code as a .japser file?

According to documentation subreportExpression can return a JasperReport object too.

Related

How to download normal word export not grid layout export from Jasper soft v6.3.1

I am using Jasper soft 6.3.1 and Jasperserver 6.3.0.
I am generating a report book using Jasper.
When I export report book into .docx report, this word file contains grid. Its not like normal document.
How I can download docx like normal ms word document?
Is there any alternative?
Do I need to go for Aspose.com solution, if yes, then how ?
Jasper will always export an docx-output in a table/grid structure. Unfortunately there is no other way.
You can achieve your requirements using Aspose.Words for JasperReports. The output document will be according to the elements of your report. Please read the documentation of Aspose.Words for JasperReports. I work with Aspose as Developer evangelist.
Yes, you will need to use a 3rd party library to achieve this. Aspose.Words or any other similar library would do the trick but I strongly suggest that you first take a look at this library that allows you to create a template in MS Word, with all the necessary formatting and placehoders for the data. At runtime this template is filled with data. You can then choose the output format in .docx, .pdf or .xps format.
// Instancing report engine, by assigning the data source
DocumentGenerator dg = new DocumentGenerator(DataAccess.GetOrderById(7));
// Generating report by specifying the report template and the resulting report (as file paths)
dg.GenerateDocument("example.docx", "example_output.docx");

How to embed JasperReport sub-report into a jar

I have a jasper (master) report embed in a jar. The report is got from a java input stream. The jasper report is made by iReport 3.7.0
In this master report, there are a few sub-reports. At the moment I have to use
Subreport Expression : $P{SUBREPORT_DIR} + "\\SubReport.jasper"
Expression Class : java.lang.String
in the iReport to make it works. It means that I store the subReport.jasper in SUBREPORT_DIR folder.
My question is, how to embed these sub-reports in the jar like the master report? And what should fill in the "Default Value Expression"? (if it is needed)
The closest question and answer so far I have seen is in here
How to load subreport resources with Jasper?
However the answer is not sufficient to me for master report compile. There is an error message saying missing sub-report when compile (and this is why I think the Default Value Expression may be needed?)
Thank you very much!
for example:
i have report and subreport, located in some *.jar file. to invoke subreport i set subreport expression
getClass().getResource("/path/to/my/report/in/a/jar/subreport.jasper").openStream()
and choose subreport expression class java.io.InputStream
it is working!
I've described one possible solution in an answer in another question. Question is not identical, but the solution solves this problem also.
That solution uses spring, but replacing spring specific parts (FileSystemResourceLoader) with Class.getResourceAsStream() should not be too big of a problem.

Linking subreports in iReport so they also work in Jasper server

Using iReport v4.0.1 with Jasperserver v4.1.0 I'm trying to find a syntax for linking subreports to the main report that lets me test it in iReport then deploy to the server through the repository browser.
The default syntax for sub-reports in iReport for the subreport expression is something like
$P{SUBREPORT_DIR} + "mySubReport.jasper"
When you deploy this from iReport it's smart enough to pick this up and suggest changing it to
"repo:mySubReport.jrxml"
and to then deploy all subreports to the Resources folder of the main report.
That's great, but unfortunately it then edits the file in iReport to save this change which means you can no longer run the report in iReport without manually re-editing all the sub-report expressions - this makes the process of testing and deploying to the server really painful, particularly when there are multiple sub-reports in a report.
I thought I could at least set the value of $P{SUBREPORT} to be "repo:" or "My\local\filepath" so that at least I'd only have one place to change it, but the compiler doesn't like that.
Is there an alternative structure or an expression that will resolve to repo:*.jrxml or My\local\filepath*.jasper correctly depending on where you're running the report from?
The best solution to this is to add an additional parameter like $P{IsOnServer}. Set the default value to true. For your subreport expression use this:
$P{IsOnServer} ? "repo:mySubReport.jrxml" : "/local/path/to/mySubReport.jasper"
When you run the report in iReport, you'll be prompted for the value of IsOnServer. Make it false; the subreport expression will resolve to your local file. On the server, don't define an input control. The users will never be prompted for that parameter (they won't even know it exists), and it will result to the desired 'repo' syntax.
An even better solution would of course be for iReport to handle this automatically... but for now you need to do something like this.

How to create jrxml for sub reporting

I want create a complex jrxml file to create PDF.
I want to put another jrxml in my jrxml file.
So.. my question is how to put one jrxml to another jrxml
My jrxml files are: salesreport.jrxml, financialreport.jrxml and report.jrxml
I want to put salesreport.jrxml and financialreport.jrxml to report.jrxml.
Usually you develop reports with iReport.
iReport has facilities for including subreports within reports (by dragging the subreport icon onto the master report page).
Note that JasperReports uses absolute paths for file references. I would recommend you set up parameters to your reports as follows:
$P{ROOT_DIR}
$P{SUBREPORT_DIR}
Give $P{SUBREPORT_DIR} a default value of $P{ROOT_DIR} + "subreports/".
At that point, you can pass the absolute path as $P{ROOT_DIR} into your report and then the subreports will be stored in a subdirectory called subreports, which is located in $P{ROOT_DIR}.
Or use the JasperCompileManager class from within the master jrxml file to dynamically compile it.
<subreportExpression><![CDATA[JasperCompileManager.compileReport($P{SUBREPORT_DIR}+"/myFile.jrxml")]]></subreportExpression>

How can I disable Parameter Prompt at run time in Crystal Report XI?

How can I disable Parameter Prompt in sub report at run time in Crystal Report XI? I used Ms VS 2005 and report also included. Other report features is the same Crystal Report features. Other report not show prompt at run time which are not included Sub report. Prompt appeared one is included sub report. so you may hv any suggestion. let me know pls. thanks.
I solved it from this web site: http://www.it-sideways.com/2011/10/how-to-disable-parameter-prompt-for.html
Take a look at this link.
Pass parameters to a stored procedure in a Crystal Report sub report?
Here are two other links that could prove helpful as well.
passing parameters in crystal report
http://www.tek-tips.com/faqs.cfm?fid=1329
We had the same issue and resolved this by modifying our code that prints the report.
Instead of setting the ReportSource of the CrystalReportViewer before setting the report parameters, set it after you have added all the report and subreport parameters.
I just solved it with something very simple, I don`t know if it works in every case but in my case it did.
Solution:
Go to Properties of your CrystalReportViewer and set ReportSource=None
Use following steps
Don't use CrystalReportViewer1.RefreshReport or CrystalReportViewer1.Refresh
Set Report source from properties to none
Report source must be assigned Dynamically
in your code have this sequence
REPORT1.Refresh()
REPORT1.SetParameterValue(0, "some default value") 'assign some default value
CrystalReportViewer1.ReportSource = REPORT1 'dynamically assigned report source