如何在Jaspersoft Server中使用csv作为数据源? [英] How to use csv as datasource in Jaspersoft Server?

查看:231
本文介绍了如何在Jaspersoft Server中使用csv作为数据源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求使用Jaspersoft studio生成报告以生成报告模板,然后使用jaspersoft服务器让用户按需生成报告,使用CSV文件中的数据,而不是数据库。



我已经能够使用工作室在本地生成报告,将报告上传到服务器,但我无法从那里生成报告。



我一直在环顾四周,提出的每个解决方案都是将数据注入数据库,然后使用它生成报告。但是在jaspersoft社区的其他帖子中,据说CSV支持将在2014年初添加,所以我猜它已经存在了。



所以,我认为可能修复它的是:



1)将CSV文件添加到服务器,但如何链接报告(.jrxml)和dataAdapter(.xml)?



现在,我已将其上传到/contentFiles/xls/energy.csv,但如果我把它放在数据适配器上,jaspersoft找不到它:





我假设因为没有ip到服务器,所以它可能认为它是一个本地文件。如果我使用ip到服务器,在我的情况下,http:// 。***:8080 / jasperserver /(*出于安全原因)并添加在那之后/contentfiles/xls/energy.csv它仍然可以找到它。那么,如何将适配器链接到服务器上的csv文件?



此外,由于此csv文件将不时生成:



2)有一个文件夹可以放置或生成要在jaspersoft服务器上更新的csv文件吗?

解决方案

要在JasperReports Server中正确部署基于文件的 dataAdapter ,需要遵循以下几个步骤。使用 Jaspersoft Studio 6.4.0 JasperReports Server Pro 6.4.0 执行以下步骤。


  1. 假设您的工作区中有CSV文件


(我正在使用


  1. 然后导出通过右键单击并选择导出到文件选项来创建新创建的适配器文件

    (我正在保存它沿着CSV文件)


  2. 此时您甚至可以从资源库资源管理器视图中删除适配器并仅保留已保存的文件,以避免任何错误。然后,您可以通过选择工作空间dataAdapter来创建报表,然后继续进行报表设计。


  3. 在此阶段将报告发布到服务器不会推送dataAdapter文件。您需要从属性面板中指定报告的默认数据适配器属性


选择工作区适配器


  1. 您现在可以将报告发布到服务器,向导将自动发现要发布的其他资源

确保在上一个对话框中选择不使用任何数据源选项




  1. 您的报告现在链接到服务器上的报告,其中包含以下属性:

     < property name =ireport.jasperserver.urlvalue =http:// localhost:8080 / jasperserver //> 
    < property name =ireport.jasperserver.uservalue =jasperadmin/>
    < property name =ireport.jasperserver.report.resourcevalue =/ public / CsvReport_files / main_jrxml/>
    < property name =ireport.jasperserver.reportUnitvalue =/ public / CsvReport/>


您可以继续使用它和Jaspersoft Studio将提示您重新发布每次保存。


  1. 您的CSV文件现在是JasperReports Server存储库资源,您可以您可以随时通过Studio或Server的UI进行更新。如果您不希望它驻留在JasperReports服务器端,您可以在创建/编辑dataAdapter文件时使用指向您文件的外部URL。


I've been asked to develop a report using Jaspersoft studio to generate the report template and then use jaspersoft server to have users that generate the report on demand, using data from a CSV file, instead of a DB.

I've been able to generate a report locally using studio, upload the report to the server, but I'm not able to generate the report from there.

I've been looking around and every solution that is proposed is to inject the data into a DB and then generate the report using that. But in other post in the jaspersoft community, it's said that CSV support is going to be added by early 2014, so I guess it's already there.

So, What I think that might fix it is:

1) Add the CSV file to the server, but how to link the report (.jrxml) and the dataAdapter (.xml)?

Right now, I've uploaded it to /contentFiles/xls/energy.csv, but if I put that on the data adaptor, jaspersoft can't find it:

I assume because there is no ip to the server, so it might think it's a local file. If I use the ip to the server, in my case, http://...***:8080/jasperserver/ (* for security reasons) and add after that /contentfiles/xls/energy.csv it still can find it. So, how to link the adaptor to the csv file on the server?

Also, since this csv file will be generated from time to time:

2) There is a folder where I can place or generate the csv file to be updated on the jaspersoft server?

解决方案

There are a couple of steps to follow in order to have a file-based dataAdapter correctly deployed in JasperReports Server. The following steps were performed with Jaspersoft Studio 6.4.0 and JasperReports Server Pro 6.4.0.

  1. Assuming you have your CSV file in your workspace

(I'm using the CsvDataSouce.txt from the csvdatasource sample)

you begin by creating the data adapter from the Repository Explorer view by pointing to your file and setting up the column names.

  1. You then export your newly created adapter to file by right-clicking it and choosing the Export To File option (I'm saving it along the CSV file)

  2. At this point you could even delete the adapter from the Repository Explorer view and keep only the saved file to avoid any mistakes. You then create your report by picking the workspace dataAdapter and continue with your report design.

  3. Publishing the report to the server at this stage would not push the dataAdapter files. You need to specify the report's Default Data Adapter property from the properties panel

by picking your workspace adapter

  1. You can now publish the report to your server and the wizard will automatically discover the additional resources to be published

Make sure you pick the Don't use any Data Source option in the last dialog

  1. Your report is now linked to the one from the server with this set of properties:

    <property name="ireport.jasperserver.url" value="http://localhost:8080/jasperserver/"/>
    <property name="ireport.jasperserver.user" value="jasperadmin"/>
    <property name="ireport.jasperserver.report.resource" value="/public/CsvReport_files/main_jrxml"/>
    <property name="ireport.jasperserver.reportUnit" value="/public/CsvReport"/>
    

You can continue to work on it and Jaspersoft Studio will prompt you to republish on each save.

  1. Your CSV file is now a JasperReports Server repository resource that you can update whenever you want, either through Studio or Server's UI. If you don't want it to reside on the JasperReports Server side you could simply use an external URL pointing to your file when creating/editing the dataAdapter file.

这篇关于如何在Jaspersoft Server中使用csv作为数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆