导出到 Excel、PDF、CSV 文件不支持阿拉伯语
我有 tomcat6 并在其中使用开放报告应用程序。 当我将任何报告导出为 Excel 或 pdf 时,它不支持阿拉伯语。 请问有人可以帮助我吗? 你可以找到下面的jsp页面代码。
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@page import="org.efs.openreports.util.DisplayProperty"%>
<%@page import="org.efs.openreports.objects.Report"%>
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<s:include value="Banner.jsp" />
<s:if test="report == null || !report.isDisplayInline()">
<a class="back-link img-report-small" href="reportList.action"><s:text name="link.back.reports"/></a>
<a class="back-link img-group-small" href="reportGroup.action"><s:text name="link.back.groups"/></a>
<br/>
<s:actionerror/>
<div align="center">
<div class="important img-queryreport" id="instructions"><s:property value="report.name"/></div>
</div>
</s:if>
<div align="center">
<s:set name="results" value="results" scope="request" />
<s:set name="properties" value="properties" scope="request" />
<s:set name="report" value="report" scope="request" />
<% DisplayProperty[] displayProperties = (DisplayProperty[]) request.getAttribute("properties");
request.setCharacterEncoding("UTF-8");
Report report = (Report) request.getAttribute("report");%>
<display:table name="results" class="displayTag" sort="list" export="true" pagesize="20" requestURI="queryReportResult.action?tab=PRODUCTIVITY" excludedParams="org.apache.struts.taglib.html.TOKEN">
<% for (int i=0; i < displayProperties.length; i++) { %>
<display:column property="<%=displayProperties[i].getName()%>" title="<%=displayProperties[i].getDisplayName()%>" sortable="true" headerClass="sortable" />
<% } %>
<display:setProperty name="export.pdf" value="true"/>
<display:setProperty name="export.xml.filename" value="<%=report.getName() + ".xml"%>"/>
<display:setProperty name="export.pdf.filename" value="<%=report.getName() + ".pdf"%>"/>
<display:setProperty name="export.csv.filename" value="<%=report.getName() + ".csv"%>"/>
<display:setProperty name="export.excel.filename" value="<%=report.getName() + ".xls"%>"/>
</display:table>
<s:if test="#session.user.scheduler">
<s:text name="queryReport.scheduleReport"/>
<a href="reportOptions.action?reportId=<%=report.getId()%>&submitSchedule=true&exportType=3">CSV</a> |
<a href="reportOptions.action?reportId=<%=report.getId()%>&submitSchedule=true&exportType=1">Excel</a> |
<a href="reportOptions.action?reportId=<%=report.getId()%>&submitSchedule=true&exportType=0">PDF</a>
</s:if>
</div>
<s:if test="report == null || !report.isDisplayInline()">
<s:include value="Footer.jsp" />
</s:if>
请快点帮我...
I have tomcat6 and use open report application in it.
when i export any report as excel or pdf, it doesn't support arabic language.
Please can anyone help me?
you can find below jsp page code.
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@page import="org.efs.openreports.util.DisplayProperty"%>
<%@page import="org.efs.openreports.objects.Report"%>
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<s:include value="Banner.jsp" />
<s:if test="report == null || !report.isDisplayInline()">
<a class="back-link img-report-small" href="reportList.action"><s:text name="link.back.reports"/></a>
<a class="back-link img-group-small" href="reportGroup.action"><s:text name="link.back.groups"/></a>
<br/>
<s:actionerror/>
<div align="center">
<div class="important img-queryreport" id="instructions"><s:property value="report.name"/></div>
</div>
</s:if>
<div align="center">
<s:set name="results" value="results" scope="request" />
<s:set name="properties" value="properties" scope="request" />
<s:set name="report" value="report" scope="request" />
<% DisplayProperty[] displayProperties = (DisplayProperty[]) request.getAttribute("properties");
request.setCharacterEncoding("UTF-8");
Report report = (Report) request.getAttribute("report");%>
<display:table name="results" class="displayTag" sort="list" export="true" pagesize="20" requestURI="queryReportResult.action?tab=PRODUCTIVITY" excludedParams="org.apache.struts.taglib.html.TOKEN">
<% for (int i=0; i < displayProperties.length; i++) { %>
<display:column property="<%=displayProperties[i].getName()%>" title="<%=displayProperties[i].getDisplayName()%>" sortable="true" headerClass="sortable" />
<% } %>
<display:setProperty name="export.pdf" value="true"/>
<display:setProperty name="export.xml.filename" value="<%=report.getName() + ".xml"%>"/>
<display:setProperty name="export.pdf.filename" value="<%=report.getName() + ".pdf"%>"/>
<display:setProperty name="export.csv.filename" value="<%=report.getName() + ".csv"%>"/>
<display:setProperty name="export.excel.filename" value="<%=report.getName() + ".xls"%>"/>
</display:table>
<s:if test="#session.user.scheduler">
<s:text name="queryReport.scheduleReport"/>
<a href="reportOptions.action?reportId=<%=report.getId()%>&submitSchedule=true&exportType=3">CSV</a> |
<a href="reportOptions.action?reportId=<%=report.getId()%>&submitSchedule=true&exportType=1">Excel</a> |
<a href="reportOptions.action?reportId=<%=report.getId()%>&submitSchedule=true&exportType=0">PDF</a>
</s:if>
</div>
<s:if test="report == null || !report.isDisplayInline()">
<s:include value="Footer.jsp" />
</s:if>
help me quickly please...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在使用从 Stripes MVC 应用程序中选取的 Displaytag 1.2 的 JBoss 下遇到了类似的问题。
当数据库 (MySQL) 提供包含以 UTF-8 编码的斯堪的纳维亚语言字符的字符串时,这些表的 CSV 和 Excel 导出已损坏,即下载的文件不包含数据或包含少量无用数据损坏的数据。
我认为与数据相关的主要问题是关于 ISO-8859-1 中的芬兰字符编码,而不是 UTF-8 中的(cfr. http://en.wikipedia.org/wiki/ISO/IEC_8859-1)。
对我有用的修复是:
将其添加到 Stripes Action Bean:
将其添加到相应的 JSP:
此后,我可以成功地从包含使用斯堪的纳维亚语言的 UTF-8 字符编码的数据的 Displaytag 表中下载 CSV 和 Excel 文件。
I got a similar issue under JBoss using Displaytag 1.2 picked from a Stripes MVC application.
When the database (MySQL) was giving strings containing Scandinavian language characters encoded in UTF-8, then the CSV and Excel exporting of those tables was corrupted i.e. the downloaded file contained no data or a small amount of useless corrupted data.
I think the main issue, data related, was regarding Finnish characters' encodings which are in ISO-8859-1 but not in UTF-8 (cfr. http://en.wikipedia.org/wiki/ISO/IEC_8859-1).
The fix that is working for me was to:
adding this to the Stripes Action Bean:
adding this to the corresponding JSP:
After this I am succesfully able to download CSV and Excel files from a Displaytag table containing data encoded with UTF-8 characters from Scandinavian languages.
经过搜索,我找到了这种情况的解决方案:
您应该添加
response.setContentType("application/vnd.ms-excel;charset=Cp1256");
而不是:
request.setCharacterEncoding("UTF-8");
在<% DisplayProperty .....>; 线
利益
After searching i found solution for this case:
You should Add
response.setContentType("application/vnd.ms-excel;charset=Cp1256");
instead of:
request.setCharacterEncoding("UTF-8");
in <% DisplayProperty .....> line
for benefit
我们使用的是 DisplayTag 1.1.1,但在 Excel/CSV 导出中遇到了特殊字符编码 (UTF-8) 的问题。经过一番搜索后,我们通过在 TableTag.java 类中的 writeExport() 导出字符串之前添加 BOM 来解决该问题。
例如:
JspWriter lOut = pageContext.getOut();
...
lOut.write('\ufeff');
lOut.write(pExportString);
此方法效果很好(正确显示特殊字符),但在 xls 输出中,所有数据都显示在 Excel 2010 的一个单元格中,尽管 CSV 输出显示正确。 \t - 添加 BOM 后 TAB 分隔符不起作用。但如果我们将 \t 替换为逗号(,),它在 Excel 2010 中将按预期工作。
We are using DisplayTag 1.1.1 and we had a problem with special character encoding (UTF-8) in Excel/CSV export. After some search's we were able to fix the issue by adding BOM before export string to writeExport() in TableTag.java class.
Ex:
JspWriter lOut = pageContext.getOut();
...
lOut.write('\ufeff');
lOut.write(pExportString);
This works well (display special characters correctly) except in xls output, all data displayed in one cell in Excel 2010 although CSV output displayed correctly. \t - TAB separator didn't work after adding BOM. But if we replace \t with Comma(,), it works as expected in Excel 2010.