我知道,通过使用<g:Jasper>
标签,我可以在 grails 中生成报告,但我想将生成的报告直接保存到文件夹中,主要是使用方法,你们中的任何人对此有什么想法吗
2 回答
2
假设您的控制器con
和方法met
执行 jasper 报告导出。在params
你传递一些参数。假设参数是name, reportFile, 'date
.
然后,您可以通过从任何位置调用此链接来获取报告导出:
http://yourDomain.com/con/met?name=myName&date=21-11-2012&reportFile=fileName
例如:我最近使用此链接导出了一份碧玉报告:
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
于 2017-02-05T06:38:11.363 回答
1
我希望您要求将 jasper 生成的报告保存到文件中。这很简单。您可以从 jasper 获取报告内容(作为字节数组)。然后只需将内容保存到文件中。下面给出一个例子——
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);
}
于 2017-07-09T12:00:49.100 回答