简体   繁体   中英

Generating jasper report by using method call in grails

我知道,通过使用<g:Jasper>标签,我可以生成grails报告,但我想将生成的报告直接保存到文件夹,主要是使用方法,你们对这个有任何想法吗?

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

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM