I have total 5 reports in 5 different files and i want to make only single excel file which contains these five reports and five different sheets how it will be possible with jasper report?
Please help
Thanks in advance
Instead of creating 5 reports just use one report and set the property net.sf.jasperreports.export.xls.one.page.per.sheet to true.
Then just rename them with net.sf.jasperreports.export.xls.sheet.name
and use the Page Break element
Search on the internet for more information if needed. There are actually a lot of examples for this.
First you have to create JasperPrint objects for each sheet as you normally would.
JasperPrint firstSheet = ...;
JasperPrint secondSheet = ...;
JasperPrint thirdSheet = ...;
JasperPrint fourthSheet = ...;
JasperPrint fifthSheet = ...;
Now JasperPrint already have the datasource at this point. Use the Arraylist to add the JasperPrint object and the exporter will use each object to create a sheet
JRXlsxExporter exporter = new JRXlsxExporter();
ArrayList<JasperPrint> list = new ArrayList<JasperPrint>();
list.add(firstSheet);
list.add(secondSheet);
list.add(thirdSheet);
list.add(fourthSheet);
list.add(fifthSheet);
exporter.setExporterInput(SimpleExporterInput.getInstance(list));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputFile));
exporter.exportReport();
And you need to use net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter as import
Related
I am developing the Invoice printing System using the Jasper report, Now I have can print the report but it will take 2000ms to load the report, also 2000ms take to start the printing,
These are I am using the JAR FILES,
commons-beanutils-1.4
commons-digester-1.7
commons-logging-1.0.3
commons-beanutils-1.4
groovy-all-1.7.5
batik-all-1.7
barcode4j-2.1
itextpdf-5.1.0
jasperreports-6.0.3
xercesImpl-2.11.0
xml-apis-ext-1.3.04
preparedStatement = conn.prepareStatement(sqlString);
resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
HashMap<String, Object> hm = new HashMap<>();
JasperDesign jasperDesign = JRXmlLoader.load(new File(
"C:/Invoice/Invoice.jrxml"));
JRDesignQuery designQuery = new JRDesignQuery();
designQuery.setText(sqlString);
jasperDesign.setQuery(designQuery);
JasperReport jasperReport = JasperCompileManager
.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(
jasperReport, null, conn);
for (int i = 0; i < copies; i++) {
JasperPrintManager.printReport(jasperPrint, false);
}
JasperViewer.viewReport(jasperPrint);
The above code I used to print the report but, getting too much time to load the report. Please suggest my fault and some other idea...
I guess the SQL query could be the problem. Have you tried executing it in a sql query tool and check how long it runs? Optimizing it should yield a performance win.
You are also running the query twice: before the report and when you are filling it via the JasperFillManager.fillReport() call.
If there are no specific reasons to check wheter the query contains any records, I would recommand to let JasperReports handle the query and the case that no record is found. You can determine a specific behaviour in that case via the "When No Data Type" property in the reportdesign.
This question is in reference of generated jasper report is not showing bar chart
I m exporting a report built in jasper reports with bar chart (template report5.jrxml) to a html file.
Code:
public showReport() throws JRException{
...
InputStream reportStream = this.getClass().getResourceAsStream("/report5.jrxml");
JRDataSource dataSource = new JRBeanCollectionDataSource(reportData);
HashMap params = new HashMap();
params.put("Title", "Report");
JasperDesign jd = JRXmlLoader.load(reportStream);
JasperReport jr = JasperCompileManager.compileReport(jd);
JasperPrint jp = JasperFillManager.fillReport(jr, params, dataSource);
JRHtmlExporter exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
//EXPORTING REPORT TO A FILE "myreport.html"
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "E:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/mywebapp/WEB-INF/jsps/reports/reportsOutput/myreport.html");
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, false);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_DIR_NAME , "E:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/mywebapp/WEB-INF/jsps/reports/reportsOutput/myreport.html_files"); exporter.setParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, true);
exporter.exportReport();
}
The generated report in output html file (myreport.html) shows text but does not show any chart.Though there is folder (myreport.html_files) generated by jasper reports API next to the output file which contains chart images.
Why generated html is not showing any chart images?
I have a really simple report, based on one of the samples, it produces something like this:
<integer> <name of group> <number of items in the group>
I want to add a hypertext link to that will open up a file containing the elements of contained in the group.
This is how I load up my report for generation:
JasperReport jasperReport = (JasperReport) JRLoader.loadObject("./report.jasper");
Map params = new HashMap();
Connection con = DriverManager.getConnection("<connection string>);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, con);
JasperExportManager.exportReportToHtmlFile(jasperPrint, "./report.html");
I use the following code to pass parameters into a CR
// Reuse myDiscreteValue, and assign second country
myParam = new ParameterField();
myDiscreteValue = new ParameterDiscreteValue();
myParam.Name = "#toDate";
myDiscreteValue.Value = RmtUtility.Utility.DisplayDate(toDate);
myParam.CurrentValues.Add(myDiscreteValue);
myParams.Add(myParam);
I get an error message "Missing Parameter Value" when I tried to export the document using CR Option.
:(
Try clearing and then setting the values of the parameters within the Report object.
Something like this:
ParameterDiscreteValue paramDV = new ParameterDiscreteValue();
paramDV.Value = RmtUtility.Utility.DisplayDate(toDate);
report.ParameterFields["#toDate"].CurrentValues.Clear();
report.ParameterFields["#toDate"].DefaultValues.Clear();
report.ParameterFields["#toDate"].CurrentValues.Add(paramDV);
Note: report being your Crystal Report Document
Well I have a Cyrstal report which has 4 sub reports on and it is linked through an ItemID column and a Culture, so it has a parameter value "?Pm-ItemID" and "?Pm-Culture" now i'm using DataSet to load the data to the Crystal Report's datasource, when I run the report its giving me an error which was an asking parameter field was not suplied, so i think my question would be what am I going to pass to those ParameterFields?
here's an idea.
ReportDocument myreport = new ReportDocument();
myreport.Load("C:\MyReport.rpt");
DataSet ds = GenerateReportData();
myreport.SetDataSource(ds);
//Loop through each to Load the DataSet
for (int i = 0; i < myreport.Subreports.Count; i++)
{
ReportDocument subreport = myreport.SubReports[i];
DataSet subds = GenerateReportData(subreport.name)
subreport.SetDataSource(subds);
}
//I can see that there's a parameterfields in myreport.ParameterFields
//As I look through inside it there are 8 ParameterFields repeating Pm-ItemID and Pm-Culture
foreach (ParameterField pf in myreport.ParameterFields)
{
myreport.SetParameterValue(pf.Name, Value???);
}
Well, I see what's wrong.
ReportDocument subreport = myreport.SubReports[i];
DataSet subds = GenerateReportData(subreport.name)
subreport.SetDataSource(subds);
should not be done this way, it should be
DataSet subds = GenerateReportData(subreport.name)
myreport.SubReports[i].SetDataSource(subds);
I don't know about Crystal, but in SSRS it works like this:
1) create a subreport and create some parameters
2) create the main report, put there the subreport and in the properties you can specify what to bind to the subreport's parameters
Conclusion: I don't think this is supposed to be set in code, rather report designer.