User Tools

Site Tools


gettingstartedwithjasperreports

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
gettingstartedwithjasperreports [2022/01/05 19:25] – [Setting Up] wikiadmingettingstartedwithjasperreports [2022/01/05 20:09] (current) – [Generate a Spreadsheet from SimpleReport] wikiadmin
Line 291: Line 291:
 </code> </code>
  
 +Go to the Test Frame of MIStudio and press the "Generate PDF" button. You will see a pdf called "SimpleReport.pdf" generated in the same directory as the SimpleReport.jasper file (the root MIStudio directory).
  
 <note tip>If you see the error:  <note tip>If you see the error: 
 net.sf.jasperreports.engine.JRRuntimeException: No secret found for "" key in "net.sf.jasperreports.data.adapter" category, you will need to add the JasperReports identity.secrets.jar https://www.ergotech.com/files/extra/identity.secrets.jar to the runtime classpath. This allows database connections to databases, such as the test database, which do not use passwords (clear passwords) </note> net.sf.jasperreports.engine.JRRuntimeException: No secret found for "" key in "net.sf.jasperreports.data.adapter" category, you will need to add the JasperReports identity.secrets.jar https://www.ergotech.com/files/extra/identity.secrets.jar to the runtime classpath. This allows database connections to databases, such as the test database, which do not use passwords (clear passwords) </note>
 +
 +That's the end of this basic Tutorial. You can also generate other report types from this same SimpleReport.jasper file (see code examples below).
 +
 +===Generate a Spreadsheet from SimpleReport===
 +
 +Instead of generating a PDF you can make an xls or xlsx report (excel spreadsheets), or a csv file.
 +
 +To make an xls spreadsheet, use this code in the JavaScript bean:
 +
 +<code javascript>
 +//Script to run SimpleReport.jasper as an XLS Excel Spreadsheet
 +
 +var HashMap = Java.type("java.util.HashMap");
 +var FileInputStream = Java.type("java.io.FileInputStream");
 +var JasperPrint = Java.type("net.sf.jasperreports.engine.JasperPrint");
 +var JasperFillManager = Java.type("net.sf.jasperreports.engine.JasperFillManager");
 +var JRXlsExporter = Java.type("net.sf.jasperreports.engine.export.JRXlsExporter");
 +var SimpleOutputStreamExporterOutput = Java.type("net.sf.jasperreports.export.SimpleOutputStreamExporterOutput");
 +var SimpleExporterInput = Java.type("net.sf.jasperreports.export.SimpleExporterInput");
 +
 +compiledReport="SimpleReport.jasper";
 +outputName = "SimpleReport.xls";
 +
 +try {
 +        reportStream = new FileInputStream(compiledReport);
 +        parameters = new HashMap(); //empty hashmap  (no parameters)      
 +        jasperPrint = JasperFillManager.fillReport( reportStream , parameters);
 +        xlsExporter = new JRXlsExporter();
 +        xlsExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
 +        xlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputName));
 +        xlsExporter.exportReport();
 +   
 +    
 +} catch (e) {
 +    print("Error in Run JasperReport script: \n"+e.stack);
 +    print(e);    
 +    
 +}
 +
 +</code>
 +
 +to make an xlsx spreadsheet, use this code in the JavaScript bean:
 +
 +<code javascript>
 +//Script to run SimpleReport.jasper as an XLSX Excel Spreadsheet
 +
 +var HashMap = Java.type("java.util.HashMap");
 +var FileInputStream = Java.type("java.io.FileInputStream");
 +var JasperPrint = Java.type("net.sf.jasperreports.engine.JasperPrint");
 +var JasperFillManager = Java.type("net.sf.jasperreports.engine.JasperFillManager");
 +var JRXlsxExporter = Java.type("net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter");
 +var SimpleOutputStreamExporterOutput = Java.type("net.sf.jasperreports.export.SimpleOutputStreamExporterOutput");
 +var SimpleExporterInput = Java.type("net.sf.jasperreports.export.SimpleExporterInput");
 +
 +compiledReport="SimpleReport.jasper";
 +outputName = "SimpleReport.xlsx";
 +
 +try {
 +        reportStream = new FileInputStream(compiledReport);
 +        parameters = new HashMap(); //empty hashmap  (no parameters)   
 +        jasperPrint = JasperFillManager.fillReport( reportStream , parameters);
 +        xlxsExporter = new JRXlsxExporter();
 +        xlxsExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
 +        xlxsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputName));
 +        xlxsExporter.exportReport();     
 +   
 +    
 +} catch (e) {
 +    print("Error in Run JasperReport script: \n"+e.stack);
 +    print(e);    
 +    
 +}
 +</code>
 +
 +to make a csv file, use this script:
 +
 +<code javascript>
 +//Script to run SimpleReport.jasper to generate a CSV file
 +
 +var HashMap = Java.type("java.util.HashMap");
 +var FileInputStream = Java.type("java.io.FileInputStream");
 +var JasperPrint = Java.type("net.sf.jasperreports.engine.JasperPrint");
 +var JasperFillManager = Java.type("net.sf.jasperreports.engine.JasperFillManager");
 +var JRCsvExporter = Java.type("net.sf.jasperreports.engine.export.JRCsvExporter");
 +var SimpleCsvExporterConfiguration = Java.type("net.sf.jasperreports.export.SimpleCsvExporterConfiguration");
 +var SimpleWriterExporterOutput = Java.type("net.sf.jasperreports.export.SimpleWriterExporterOutput");
 +var SimpleExporterInput = Java.type("net.sf.jasperreports.export.SimpleExporterInput");
 +
 +compiledReport="SimpleReport.jasper";
 +outputName = "SimpleReport.csv";
 +
 +try {
 +        reportStream = new FileInputStream(compiledReport);
 +        parameters = new HashMap(); //empty hashmap  (no parameters)      
 +        parameters.put("IS_IGNORE_PAGINATION", true);
 +        jasperPrint = JasperFillManager.fillReport( reportStream , parameters);
 +        csvExporter = new JRCsvExporter();
 +        csvExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
 +        csvExporter.setExporterOutput(new SimpleWriterExporterOutput(outputName));
 +        csvConfiguration = new SimpleCsvExporterConfiguration();
 +        csvConfiguration.setWriteBOM(true);
 +        csvConfiguration.setRecordDelimiter("\r\n");   
 +        csvExporter.setConfiguration(csvConfiguration);
 +        csvExporter.exportReport();   
 +    
 +} catch (e) {
 +    print("Error in Run JasperReport script: \n"+e.stack);
 +    print(e);    
 +    
 +}
 +
 +
 +
 +</code>
 +
 +
 +===Run the SimpleReport from TransSECS===
 +
 +You can trigger a script in TransSECS Devices with a CEID (Collection Event) or any other trigger to run the same reports as you can run in MIStudio and MIX. Copy the files listed in the setup section to your TransSECS project's resources directory. These files will be copied to the deployment when you build your TransSECS project.
 +
 +
 +
  
gettingstartedwithjasperreports.1641428753.txt.gz · Last modified: by wikiadmin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki