IREPORT +jasperreport 做报表时 对于 $Fxxxx传值很长的情况下,怎么让它自动换行呢?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IREPORT +jasperreport 做报表时 对于 $Fxxxx传值很长的情况下,怎么让它自动换行呢?相关的知识,希望对你有一定的参考价值。
类似这种情况,服务器在windows下,这种框可以自动换行,但在linux下却只显示第一行信息到框最右边剩下的就不显示了,求教这种问题怎么解决??Stretch With Overflow这个选项钩选了也没用。
最近刚刚学习jasperreport报表使用,做了几个例子,但在实现动态添加元素(列名,循环数据)上出现了问题,没办法解决.但是出现这种异常,感觉自己没什么错,查了很久的资料还找不到答案,各位帮下忙.
net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :
1. Field not found : Field1
这是设计
[img=http://f18.yahoofs.com/users/4806be90z2166bf67/86a5/__sr_/52b4.jpg?phA0C.IBEdd4GMmG][/img]
保存设计,名domeDynamic.jrxml.
代码
int randomNum = new Random().nextInt(20);
String jrxmlPath = this.getServletContext().getRealPath("/jasper");
jrxmlPath = jrxmlPath + "\\domeDynamic.jrxml";
JasperDesign jasperDesign= JRXmlLoader.load(jrxmlPath);//因为还是添加元素进去,所以还只是jrxml文件
JRDesignBand columnHeaderBand = (JRDesignBand )jasperDesign.getColumnHeader();//获取ColumnHeader拦
JRDesignBand detailBand = (JRDesignBand )jasperDesign.getDetail();//获取Detail拦
JRDesignTextField detailField= (JRDesignTextField )detailBand.getElementByKey("textField-2");
JRDesignStaticText columnHeaderField = (JRDesignStaticText)columnHeaderBand.getElementByKey("staticText-3");
Map map = new HashMap();
List list = new ArrayList(); 数据集 list.add(map);
map.put("Field1","1");
map.put("Field2","2");
//根据随即生成的数进行动态添加列
for(int i=0,y=3;i<=randomNum;i++,y++)
String detailFieldKey = "Field-"+y;
//String columnHeaderFieldKey = "staticText-"+y+1;
map.put(detailFieldKey,y);
//map.put(columnHeaderFieldKey,"列"+y);
detailField= (JRDesignTextField)detailField.clone();
detailField.setX(detailField.getX()+detailField.getWidth());
JRDesignExpression expression = new JRDesignExpression();
expression.setText("$F"+detailFieldKey+"");
System.out.println("$F"+detailFieldKey+"");
expression.setValueClass(java.lang.String.class);
detailField.setExpression(expression);
detailBand.addElement(detailField);
columnHeaderField = (JRDesignStaticText)columnHeaderField.clone();
columnHeaderField.setX(columnHeaderField.getX()+columnHeaderField.getWidth());
columnHeaderField.setText("列"+y);
columnHeaderBand.addElement(columnHeaderField);
list.add(map);
System.out.println(list);
JRDataSource jRDataSource = new JRMapCollectionDataSource(list); //用这个应该可以
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);//编译jrxml文件,异常也出在这一行.
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,null,jRDataSource); //填充打印
OutputStream outputStream = response.getOutputStream();
response.setContentType("application/pdf");
response.setCharacterEncoding("GB2312");
response.setHeader("Content-Disposition","attachment; filename="+URLEncoder.encode("PDF报表","GB2312")+".pdf");
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,outputStream);
exporter.exportReport();
outputStream.close();
out.clear();
out = pageContext.pushBody();
异常:
net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :
1. Field not found : Field1
2. Field not found : Field2
3. Field not found : Field-3
4. Field not found : Field-4
5. Field not found : Field-5
6. Field not found : Field-6
7. Field not found : Field-7
8. Field not found : Field-8
at net.sf.jasperreports.engine.design.JRAbstractCompiler.verifyDesign(JRAbstractCompiler.java:260)
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:144)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:219)
at org.apache.jsp.domeDynamic_jsp._jspService(domeDynamic_jsp.java:138)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
碰到过这问题的帮忙解决下! 谢谢呀。
顺便问一下 如果一个报表要使用多个数据源. 也就是多个Detail的情况下要怎么做? 参考技术A 有个属性,选中要换行的字段,里面有个属性是自动换行的,就是你上面的这个Stretch With Overflow,还要选那个Stretch Type才会生效,你试试看追问
选了还是不行 只能补几个空格让它换行了
本回答被提问者采纳以上是关于IREPORT +jasperreport 做报表时 对于 $Fxxxx传值很长的情况下,怎么让它自动换行呢?的主要内容,如果未能解决你的问题,请参考以下文章