1

I know,By using <g:Jasper> tag I can generate report in grails but I want to save the report generated directly to a folder,mostly using method, iss any of you have any Idea regarding this

Abdulla I
  • 11
  • 3

2 Answers2

2

Let's say your controller con and method met execute the jasper report export. And in params you pass some parameters. Let's say the parameters are name, reportFile, 'date.
Then you can get the report export by calling this link from any where:

http://yourDomain.com/con/met?name=myName&date=21-11-2012&reportFile=fileName

For example: I recently exported a jasper report using this link:

http://localhost:9096/WebSite/agent/agentTouchExport?_format=XLSX&_name=Export+to+xlsx&_file=AgentTouchReport&distributorWallet=&srWallet=&agentWallet=&businessRegionId=0&businessAreaId=0&businessTerritoryId=0&fromDate=2017-01-01&toDate=2017-02-03
goto
  • 7,908
  • 10
  • 48
  • 58
naimul64
  • 133
  • 3
  • 17
1

I hope you are asking to save jasper generated report to a file. This is easy. You can obtain report content (as byet array) from jasper. Then just save the content to a file. An example is given below-

JasperService jasperService;

def saveReport(GrailsParameterMap params, Locale locale, List<DataModel> models) {
    // Prepare data
    List searchReportSheet = new ArrayList();
    LinkedHashMap<String, Object> searchSheetMap;
    models.each {
        searchSheetMap = new LinkedHashMap<String, Object>();
        searchSheetMap.put("key", it.keyValue);
        ...............
        ...............
        searchReportSheet.add(searchSheetMap);
    }

    // Call jasper for generate report
    def reportDef = jasperService.buildReportDefinition(params, locale, [data: searchReportSheet]);

    // Save to File
    def content = reportDef.contentStream.toByteArray();
    FileOutputStream fileOuputStream = new FileOutputStream(fileDest)
    fileOuputStream.write(content);
}
Emdadul Sawon
  • 5,730
  • 3
  • 45
  • 48