Jump to content
Changes to the Jaspersoft community edition download ×

Ignore Page Width Depending on File Export Type

Go to solution Solved by imoehld,

Recommended Posts

I am attempting to create a report with a crosstab that will ignore the width of the page when exported to Excel, but won't ignore the width of the page when exported to PDF. I am setting the report's ignore width property:

<propertyExpression name="net.sf.jasperreports.crosstab.ignore.width"><![CDATA[$P{Format}.equals("XLS") ? ("true") : ("false")]]></propertyExpression>[/code]

This is set at the top of the page with the other <property> tags. In my parameters, I also have:

<parameter name="Format" class="java.lang.String"/>[/code]

When we run this report with Java code and pass a value into the format parameter, this code never ignores the width of the page (even when we assign Format="XLS"). However, if I run this in Jaspersoft Studio, this code will work as long as I have isForPrompting="true" (if it is false and I assign a default value, this code also fails to work).

Is this because I am referencing the parameter before it is defined? If so, where should I move the property expression to get this code to work?

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

I believe what I am trying to do is impossible, per a couple sources:



So, I have transitioned to trying to complete this in Java code. I have run across this example that seems to be exactly what I want:


However, for some reason this solution doesn't work for me (possibly due to the fact that the solution is 9 years old). I do not have access to the JasperReport object, but I have access to a JasperPrint object, which also has a setProperty(String, String) method. Trying to set "JRCrosstab.PROPERTY_IGNORE_WIDTH" to "true" doesn't do anything. I also tried to use an JRXlsExporter's getPropertyUtil() to get access to the propertyUtil's setProperty(String, String) method, but this also doesn't work.

Any suggestions on how to get this to work?

Link to comment
Share on other sites

  • 3 weeks later...
  • Solution

I got this to work by setting the IS_IGNORE_PAGINATION parameter to false when our format was "PDF" and to true when our format was anything else:

if(format.equals("PDF")){      parameters.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.FALSE); } else {      parameters.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE); }[/code]

Where "parameters" is the Map<String, Object> that is sent to Jasper.

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