Jump to content

[Resolved] Report (JDBC) + Subreport (Excel)


max_max_mir

Recommended Posts

Hope this helps someone.

I would like to create a main report, which gets its data from a relational database (using a JDBC connection), but want my subreport to get its related data from an Excel spreadsheet.

Creating the main report is straightforward. For the subreport, you have to use the Excel Data Source to get the data.

1. To pass the Excel Data Source to your subreport, select the subreport and under Properties -> Connection Type, select "Use a datasource expression".

2. In Data Source Expression, enter new net.sf.jasperreports.engine.data.JRXlsDataSource(new File("C:\\Path\\To\\Excel_File.xls")). This will create a new instance of the datasource.

3. In your Subreport, use COLUMN_0, COLUMN_1 etc as the fields.

4. Everything from Excel is of type java.lang.String. So if you are passing parameters to your subreport, make sure you typecast them to String.

Link to comment
Share on other sites

  • 7 months later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

And thanks, what you have put will be very helpful for subReports.

I am running into another difficulty dealing with "Excel as a Datasource", (using the standalone iReports 4.01).

I create the Excel database connection, but when I try to see the fields in the inspector, they don't show up.

From another dialog, I can see the data from Excel, and displays it in a JTable.

But still not able to access the fields to put on the report page.

I saw a kind error that said that "this is not a JDBC source" , something like that.

But I did not use that option, I used the option for Excel.

Also I have another problem with the way it grabs data from Excel.

It assumes that your data basically starts in row1(+ or - a header).

My excel sheets, the tabular data starts from row 20, the previous rows contain account details/description of what the

data is.

Question:

1) how do you tell iReports to start looking at the data from a particular row.

2) I have multiple sheets with data in a workBook, how do i traverse and look at the different sheets.

Your help will be greatly appreciated.

Sincerely,

Paluee

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

  • 2 months later...

Hi,

I have a main report through which i want to access subreport.Im using excel sheet as datasource for subreport .when i compile subreport individually it provides me answer but when i try to see answer through mainreport its showing me blank pages.Can anyone help me out in this?

Link to comment
Share on other sites

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...