簡體   English   中英

使用grails中的方法調用生成jasper報告

[英]Generating jasper report by using method call in grails

我知道,通過使用<g:Jasper>標簽,我可以生成grails報告,但我想將生成的報告直接保存到文件夾,主要是使用方法,你們對這個有任何想法嗎?

假設您的控制器con和方法met執行jasper報告導出。 params你傳遞一些參數。 假設參數是name, reportFile, 'date
然后,您可以通過以下任何位置調用此鏈接來獲取報告:

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

例如:我最近使用此鏈接導出了一個jasper報告:

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

我希望您要求將jasper生成的報告保存到文件中。 這很容易。 您可以從jasper獲取報告內容(作為byet數組)。 然后只需將內容保存到文件中。 下面給出一個例子 -

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM