浏览 2677 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-12-17
目前网上谈到较多的是一种方法,且多为转载;对其源代码进行分析后进行了另一种改造;具体如下: displaytag-1.1\displaytag\src\main\java\org\displaytag\render\ItextTableWriter.java ItextTableWriter: -- private Font getFont(float size, int style, Color color) { Font font = null; try { font = new Font(BaseFont.createFont("STSong-Light"/* "Helvetica" */, "UniGB-UCS2-H"/* BaseFont.WINANSI */, false), size, style, color); } catch (Exception e) { e.printStackTrace(); } finally { if (font == null) { font = FontFactory.getFont(FontFactory.HELVETICA, size, style, color); } } return font; } 更改所有的getFont方法使用上边的getFont方法,以下仅为其中一例 protected Font getTableFont() { return getFont(10, Font.NORMAL, new Color(0x00, 0x00, 0x00)); } 这样更改后,导出的报表标题和footer都是中文了。 二、添加二级标题或者是报表头功能 (1)在displaytag-12.tld中添加以下代码 <tag> <name>header</name> <tag-class>org.displaytag.tags.TableHeaderTag</tag-class> <body-content>JSP</body-content> <display-name>header</display-name> <description> Tag which should be nested into a table tag to provide extra header row(s). The body of the tag will be inserted before the automatically-generated header row, within the thead tag. </description> <attribute> <name>media</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> Use this attribute to keep a header from being output during an export. The caption will only render for the named media type(s) - it won't be added to the table if the current request media is not supported. Can be any space separated combination of 'html', 'csv', 'xml', 'all', or 'excel'. Defaults to 'all'. See the export page in the example webapp for more details. </description> </attribute> <example> <![CDATA[ <display:table name="someList" varTotals="totals"> <display:column property="itemName"/> <display:column property="price" total="true"/> <display:header> <tr> <td>Total Bill:</td> <td><c:out value="${totals.column2}" /></td> <tr> </display:header> </display:table> ]]> </example> </tag> (2)在display中添加相应代码 <1>添加src/main/java/org/displaytag/tags/TableHeaderTag.java类。 <2>src/main/java/org/displaytag/model/TableModel.java修改 : 添加private String header属性,并生成set、get方法; 在toString()增加.append("header", this.header) //$NON-NLS-1; <3>src/main/java/org/displaytag/render/HtmlTableWriter.java if (model.getHeader() != null) { write(model.getHeader()); } <4>src/main/java/org/displaytag/tags/TableTag.java 添加private String header属性,并生成set、get方法; 置空方法中添加this.header = null; 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |