Ignore Page Width Depending on File Export Type

0

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>

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"/>

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?

imoehld's picture
Joined: Aug 12 2019 - 10:05am
Last seen: 1 week 1 day ago

I can confirm that the "Format" parameter is being set, as toward the bottom of the page I have:


<printWhenExpression><![CDATA[!$P{Format}.equals("XLS")]]></printWhenExpression>

This works exactly as expected.

imoehld - 1 week 3 days ago

1 Answer:

0

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

https://community.jaspersoft.com/questions/976451/set-report-properties-expression

https://community.jaspersoft.com/wiki/how-configure-jasperreports-server-not-truncate-adhoc-crosstabs-columns

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:

https://community.jaspersoft.com/questions/534046/excel-report-crosstab

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?

imoehld's picture
Joined: Aug 12 2019 - 10:05am
Last seen: 1 week 1 day ago
Feedback
randomness