ylva.degerfeldt Posted March 2, 2016 Posted March 2, 2016 Hi,I'm using JasperReports Server v.5.5.0 at my job and I'm creating a report that will be exported to Excel format.The customer that I'm creating the report for doesn't want the title to be shown in only one, long, merged column (in Excel).So how could I make it span across multiple columns when exporting to Excel?I've googled a bit and I found the parameter:cnet.sf.jasperreports.export.xls.column.widthand its description here:http://jasperreports.sourceforge.net/config.reference.html#net.sf.jasperreports.export.xls.column.widthbut I still don't know how to use it. If this property could solve the problem, I would like to know exactly where and how to put it in the jrxml source file.I've tried to find an answer to this, but I haven't found one.Also, I don't want some property that changes the column width of All columns in the report (when exported to Excel), just something that affects the title./Ylva
szaharia Posted March 2, 2016 Posted March 2, 2016 Hi,Attached is an Excel file with 2 examples of a long text spanning over multiple columns:to get the layout illustrated in example (1) you need to set the following properties for the textfield:net.sf.jasperreports.print.keep.full.text = truenet.sf.jasperreports.export.xls.wrap.text = falseto get the layout illustrated in example (2) just set the texfield width wide enough to make place for the entire text on a single lineI hope this helps,Sanda
ylva.degerfeldt Posted March 4, 2016 Author Posted March 4, 2016 Thank you, Sanda!Example 1 is what I want.But could you help me by showing me exactly how and where to put these properties in the jrxml code?I've tried putting them as attributes to both the reportElement and the textElement I have for my title, like:<textElement textAlignment="Center"net.sf.jasperreports.print.keep.full.text = "true"net.sf.jasperreports.export.xls.wrap.text = "false">[/code]but Jaspersoft studio complains about that:"Attribute 'net.sf.jasperreports.print.keep.full.text' is not allowed to appear in element 'textElement'.I've also tried specifying them as properties inside my "textElement" element like: <textElement textAlignment="Center"> <property name = "net.sf.jasperreports.print.keep.full.text" value = "true"/> <font size="16" isBold="false"/> </textElement>[/code] but Jasperstudio complains about that too:"Invalid content was found starting with element 'property'. One of '{"http://jasperreports.sourceforge.net/jasperreports":font, "http://jasperreports.sourceforge.net/jasperreports":paragraph}' is expected. "So how do I specify these properties just for my title text element? (I don't want them for the entire report.)Thanks in advance!/Ylva
szaharia Posted March 7, 2016 Posted March 7, 2016 Hello Ylva,These properties have to be placed within the <reportElement /> section:<textField> <reportElement x="..." y="..." width="..." height="..." uuid="..."> <property name="net.sf.jasperreports.print.keep.full.text" value="true"/> <property name="net.sf.jasperreports.export.xls.wrap.text" value="false"/> </reportElement> <textElement> <font size="14"/> </textElement> <textFieldExpression><![CDATA["Your very long text here"]]></textFieldExpression></textField>[/code]Adding properties by direct editing the JRXML source may lead to issues like you described. To avoid such troubles, just click on the element in JSS editor and go to Properties pane --> Advanced --> Edit Properties. Add these properties there and they will be automatically transfered to the element in a safe manner.Regards,Sanda
ylva.degerfeldt Posted March 7, 2016 Author Posted March 7, 2016 Thanks again, Sanda!But I'm afraid that didn't work for me.Now the title part of my jrxml looks like this: <staticText> <reportElement x="0" y="0" width="929" height="30" uuid="434595fa-21e2-479a-98a2-a7592ef73860"> <property name="net.sf.jasperreports.print.keep.full.text" value="true"/> <property name="net.sf.jasperreports.export.xls.wrap.text" value="false"/> </reportElement> <textElement textAlignment="Center"> <font size="16" isBold="false"/> </textElement> <text><![CDATA[My report title..]]></text> </staticText>[/code]But after I published my updated report, ran it and exported it to xls-format, the title was still inside one long merged column.Are these properties supposed to work with JasperReports Server 5.5.0?
szaharia Posted March 7, 2016 Posted March 7, 2016 I assume this is because of the width="929" setting. This is quite a large value, enough to produce merged cells if there are other smaller report elements placed below this title.Just set the element width with an appropriate smaller value (for instance, width="100") and see the difference.For a more precise estimate of the element width we need to see the JRXML file, because the Excel export is very sensitive to the report design itself. You'd probably need both to resize the element and place it in a proper position.Regards,Sanda
ylva.degerfeldt Posted March 9, 2016 Author Posted March 9, 2016 It seems like I have to have a width that large, partly because my title is that long and I want all of it to be shown when I run the report, and partly because I got some Excel export problems when the title width didn't exactly match the combined width of my column headers (and Detail data). Then I got unwanted merged columns in some places. But I think that was what you were referring to, Sanda..I thank you for the answers, but I'm afraid I can't spend more time on this right now.Regards,Ylva
szaharia Posted March 9, 2016 Posted March 9, 2016 Hello Ylva, and thank you for the feedback.In case of further needs, here are some guidelines about how to improve/optimize your report design layout in order to obtain an accurate Excel output. Also, attached is a JRXML report layout sample, containing a long title without merge, column headers, detail and column footer. It can be run with a 10-records empty data source.Regards,Sanda
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