Jump to content
We've recently updated our Privacy Statement, available here ×

Dynamic Sheet Names For XLS Export


rlfisherpbtgroup.com

Recommended Posts

Hello -

I am struggling to get names dynamically applied to my worksheets.  I have been successful in getting the multiple worksheets, but the labels are just Page 1, Page 2, etc.  I have read many posts on this, and it appears that I am doing everything correclty, but it still is not working.

I have set property name="net.sf.jasperreports.export.xls.one.page.per.sheet" value="true">/property>

I have set propertyexpression name="net.sf.jasperreports.export.xls.sheet.name">!--[CDATA[$F{course_name}]]-->/propertyexpression> in a variety of elements, including to the subreport that actually generates the spreadsheet, but I am only getting "Page n" for the labels.

(omitted opening angle brackets for this post)

I am probably missing something obvious here - can somebody please give me a boost?

Thank you

Link to comment
Share on other sites

  • Replies 11
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

 

It might be a matter of JR version here.

The net.sf.jasperreports.export.xls.sheet.name property is available for Excel 2003 (XLS) output starting with JR 4.1.3

For Excel 2007/2010 (XLSX) output, the property was enabled in JR 4.6.0

 

To identify other possible causes of the issue, please post a test sample that reproduce the problem.

 

Thank you,

sanda

Link to comment
Share on other sites

Try to place a hidden line element with the sheet name property in the group header:



<line>


<reportElement x="0" y="-1" width="1" height="1">


<propertyExpression name="net.sf.jasperreports.export.xls.sheet.name"><![CDATA[$F{course_name}]]></propertyExpression>


</reportElement>


</line>

 

 

 

 

 

Link to comment
Share on other sites

Thank you again for your helpful replies. I had early-on tried the line element idea (from a post I found somewhere) and it didn't work. I tried it again now, with a simplified example report, and the tab names appeared.

 

What I have determined is that the property appears to be ignored when the group contains a subreport (which is the whole notion desired around separate worksheets).

Link to comment
Share on other sites

Subreport elements are "consumed" during the report filling, so they cannot be used to preserve export-time properties. Elements that can be properly used for this purpose are: line, rectangle, ellipse, static text, textfield, image, frame and generic element. Don't try this with subreports, breaks or crosstabs.


For instance, another good solution is to place the subreport in a frame and set the sheet name property on the frame element.



Kind regards,


sanda

Link to comment
Share on other sites

Hi,


While testing I couldn't reproduce this behavior:



"but if the group header has line (with propertyexpression), subreport, break then I only get Page 1, Page 2, Page 3"



I tested it on a local sample (very similar to the attached sample.jrxml file) that also comes with a combination of isIgnorePagination="true", subreport and break element, and problem just got solved by adding a hidden line element, as previously shown. I also used JR-4.5.0 for testing



On the other hand, you mentioned that when you used a simplified sample, it worked.

In this case, could you post your initial sample here, the one that didn't work? Maybe we could find out the root cause of the issue.


Thanks,


sanda

Link to comment
Share on other sites

Well, didn't test it yet, but at a glance I noticed that both line and subreport are positioned at x=0 and y=0 in the new sample.jrxml. That means they are overlapping elements and could lead to unexpected results when exported to a grid. Just try to set y=-1 for the line element, and see if the problem got solved.


I hope this helps,


sanda

Link to comment
Share on other sites

  • 2 years later...

Try to place a hidden line or Text element with the sheet name property in the group header: 

<line> 
<reportElement x="0" y="-1" width="1" height="1"> 
<propertyExpression name="net.sf.jasperreports.export.xls.sheet.name"><![CDATA[$F{course_name}]]></propertyExpression> 
</reportElement> 
</line>

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