Jump to content
Changes to the Jaspersoft community edition download ×

How to get the excel report name dynamically and use it in jasper


vamsikrishna

Recommended Posts

Hi

     How can i get excel report name dynamically?

I am trying to use <propertyExpression>, but am not able to get. Am getting error if i use <propertyExpression> tag .Is there any possibility in jasper for resolveing this. Please help me. Its very urgent

Thanks in advance

Regards

Vamsi Krishna

   

Link to comment
Share on other sites

  • Replies 12
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

     Am generating the report using java code. From java code am passing xls report name as parameter. I want to make use of this parameter value to set the name of report. My main objective is to set  "net.sf.jasperreports.export.xls.sheet.names.all" property using a paramenter value. And i dont want to set  "JRXlsAbstractExporterParameter.SHEET_NAMES" parameter in java.

Thanks in Advance

Link to comment
Share on other sites

another option here it is to set it using JRProperty class proivded
you can pass the property name and its value using getter and setter method.

net.sf.jasperreports.engine.util.JRProperties

 

if it do not get overridden then try to alter the properties file itself and put in jar back. (last option)



Post Edited by rajendratambat at 11/19/2010 07:05
Link to comment
Share on other sites

Hi I will explain u my probelm clearly now

My project is having many reports. In those,two reports are using same jrxml. And i wrote separate java file which contains the logic for generating the reports. So i cant use JRProperties class here. Am passing all the column headers and parameters to the report through a separate service(each report has separate service class)class. So now suggest me the ways how i can pass the report name from this service class and use it in jasper.

I think u got my problem now

Please help in this regard

Link to comment
Share on other sites

I feel you need to set the worksheet names in the excel. right?... if so then please check the following code that you need to add in your service classes.


hope this solves your prob...

Code:
JRXlsExporter  xx = new JRXlsExporter();String[] sheetNames = {"rSheet1","rSheet2", "Rs3"}; // depending uppon no. of worksheets you have createdxx.setParameter(JRXlsExporterParameter.SHEET_NAMES, sheetNames );xx.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);xx.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "C:\\report.xls");xx.exportReport();
Link to comment
Share on other sites

Ya rajendra i can go with that code. As i told my java code for generating reports is common for all the reports. The code which u gave will affect the other reprots if i chage that common java file(code used to generate report) . Suggest me a way where i can pass report name as parameter from a java class(called service class in my report) without using jasper properties in java. So that i can retrieve that report name in jasper and make use of it.

 

Link to comment
Share on other sites

I didn't get you,  when you said for different report you have service classes which generate report dynamically.

can't you pass the report names as a string array to service class and service class can pass that array to your exporter...

as I have mentioned earlier... that was just an example for you to show...

you can very well replace that (sheetname[]) with array object instead of  passing static names...

if possible can you let me know you is your flow is going and what are your service classes do..

 

Link to comment
Share on other sites

Hi rajendra,

    The request flow is like this. UI--->ReportServlet------->Service Class----------->Generate report. This flow is common for all the reports.  From UI request is going to ReportServlet where am deciding which jrxml to load and set all required things to send them to database. In Service class am setting all the report column header names as parameters which am going to retrieve in jasper. And the GenerateReport class will set required properties like IS_IGNORE_CELL_BORDER, IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, IS_ONE_PAGE_PER_SHEET etc.

          This Generate report class is common for all the reports. So i cant add the code here to set sheet name. The only option i have is to send the sheet name as parameter(like column headers) and make use of it in jasper by using "net.sf.jasperreports.export.xls.sheet.names.all" property. But problem am facing here is "How can i set a parameter value(sheet name which is sent dynamically from java side to jasper) to a property like net.sf.jasperreports.export.xls.sheet.names.all".

As per my requirement i dont have an option to set the sheet name in the java side.

 

Link to comment
Share on other sites

which class decides what sheet names required?

in your common class generatereport can't you override method passing addtional parameter? or assuming that you are getting names there and  then simply use if condition to check if names is not null then only set  property?

in other case

can you try using System.setProperty("net.sf.jasperreports.export.xls.sheet.names.all") ; if it works? or

use JRProperties class in your generatereport class depending if value of names is not null.

Hope this help

Link to comment
Share on other sites

hi

my problem is solved by usingSHEET_NAMES, sheetNames);

 

 

Earlier i tried sheetNames as a String.So am not able to get the sheetnames as i desired. Then i change sheetNames as an array then am able to get the sheetnames as i desired. 

Thanks for the timely help



Post Edited by vamsi2250 at 11/29/2010 05:36
Link to comment
Share on other sites

  • 8 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...