Jpivot mdx查询编辑器和Jpivot导出PDF、Excel中文乱码问题

一、Jpivot mdx查询编辑器输入时的中文乱码问题

下载Jpivot1.8部署后,使用jpivot mdx查询编辑器,输入带有中文的查询会返回乱码并报错。究其原因是页面request的content编码格式是iso-8859-1,要一劳永逸的解决此类问题,可以按以下步骤改动相关文件:

1.在web.xml中加入以下代码:

<filter>
		<filter-name>Set Character Encoding</filter-name>
		<filter-class>com.tonbeller.wcf.charset.CharsetFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>Set Character Encoding</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	<filter>
2. 修改WebRoot目录下的testpage.jsp的两处charset为charset=UTF-8,修改后的两处分别为:<%@ page session="true" contentType="text/html; charset=UTF-8"%>和<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">修改后问题就不会再出现了。

二、Jpivot中输出pdf打印汉字、excel导出中文时的乱码问题

jpivot是目前用得最多得OLAP展现工具,pentaho,spagoBI,openi等都是用他来做展现,jpivot中pdf打印输出中文

1.升级com.tonbeller.jpivot.print.PrintServlet文件到JPivot1.6.0以上,如果不想升级就修改PrintServlet,在init方法中增加以下语句.

public void init(ServletConfig config) throws ServletException {   
    super.init(config);   
    try {   
      // set base FOP FONT directory.  The font config  stuff will be looked for here   
      Configuration.put("fontBaseDir", config.getServletContext().getRealPath("/WEB-INF/jpivot/print/"));   
      // get the physical path for the config file   
      String fopConfigPath = config.getServletContext().getRealPath("/WEB-INF/jpivot/print/userconfig.xml");   
      // load the user proerties, contining the CustomFont font.   
      new Options(new File(fopConfigPath));   
    } catch (FOPException e) {   
      e.printStackTrace();   
      logger.info("FOP user config file not loaded");   
    } catch (Exception e) {   
      e.printStackTrace();   
      logger.info("FOP user config file not loaded");   
    }   
  }   

2.在WEB-INF\jpivot\print目录下建立userconfig.xml文件。内容如下:(仅配置黑体)

<configuration>
	<fonts>
		<font metrics-file="simhei.xml" kerning="yes" embed-file="simhei.ttf">
			<font-triplet name="SimHei" style="normal" weight="normal" />
			<font-triplet name="SimHei" style="normal" weight="bold" />
			<font-triplet name="SimHei" style="italic" weight="normal" />
			<font-triplet name="SimHei" style="italic" weight="bold" />
		</font>
	</fonts>
</configuration>
3. 下载Apache的FOP包,解开fop-0.20.5.jar,启用cmd,并到它的目录中,执行:

java org.apache.fop.fonts.apps.TTFReader -ttcname SimHei C:\WINDOWS\Fonts\simhei.ttf simhei.xml

然后就会生成需要的两个字体描述文件:simhei.xml

4. 将simhei.xml,以及simhei.ttf文件放到WEB-INF\jpivot\print目录下。

5. 修改WEB-INF\jpivot\table目录下的fo_mdxtable.xsl文件,把所有的font-family对应成SimHei

jpivot excel导出中文

Excel中不支持UTF-8, Excel输出对应的xsl文件是:../web-inf/jpivot/table目录下的xls_mdxtable.xsl

只要这个文件的encoding换为GBK就可以了.

原文一传送门:http://juxuan.fu.blog.163.com/blog/static/1121292592010916113657507/

原文二传送门:http://www.iteye.com/topic/80801

fop-0.20.5.jar下载地址:http://mirrors.ibiblio.org/maven/fop/jars/fop-0.20.5.jar

解决jpivot导出PDF汉字显示"#"问题

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值