imoehld Posted August 12, 2019 Share Posted August 12, 2019 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 More sharing options...
imoehld Posted August 13, 2019 Author Share Posted August 13, 2019 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. Link to comment Share on other sites More sharing options...
imoehld Posted August 13, 2019 Author Share Posted August 13, 2019 I believe what I am trying to do is impossible, per a couple sources:https://community.jaspersoft.com/questions/976451/set-report-properties-expressionhttps://community.jaspersoft.com/wiki/how-configure-jasperreports-server-not-truncate-adhoc-crosstabs-columnsSo, 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-crosstabHowever, 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 More sharing options...
Solution imoehld Posted August 30, 2019 Author Solution Share Posted August 30, 2019 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now