设为首页收藏本站

birt家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 891|回复: 0

[birt4.6] birt导出中文报表名称

[复制链接]
发表于 2017-5-17 17:38:10 | 显示全部楼层 |阅读模式
首先是要搞到viewservert的源码。

然后定义自己的文件名称生成类,大概是这样的:
public class JpmsFilenameGenerator implements IFilenameGenerator
{

public static final String DEFAULT_FILENAME = "BIRTReport"; //$NON-NLS-1$

public JpmsFilenameGenerator()
{

}

/**
* @see org.eclipse.birt.report.utility.filename.IFilenameGenerator#getExportFilename(String,String,Map)
*/
public String getFilename( String baseName, String extension, String outputType, Map options )
{
String exportName = _getExportName(options);
if(exportName !=null && !"null".equalsIgnoreCase(exportName)){
baseName = exportName;
}
return makeFileName( baseName, extension );
}

private String _getExportName(Map options) {
String exportName=null;
Object obj = options.get("httpRequest");
if(obj !=null && obj instanceof RequestFacade){
RequestFacade request = (RequestFacade)obj;
exportName = ParameterAccessor.getParameter(request,"__exportName");
}
return exportName;
}

/**
* Makes a filename using the target extension from the options.
* @param fileName file name which extension must be replaced
* @return file name with replaced extension
*/
public static String makeFileName( String fileName, String extensionName )
{
String baseName = fileName;
if (baseName == null || baseName.trim().length() <= 0)
{
baseName = DEFAULT_FILENAME;
}

baseName +="_" + new SimpleDateFormat("yyyyMMdd").format( new Date() );

// append extension name
if (extensionName != null && extensionName.length() > 0) {
baseName += "." + extensionName; //$NON-NLS-1$
}
return baseName;
}


}
然后在web.xml里添加下面的配置:
<context-param>
<param-name>BIRT_FILENAME_GENERATOR_CLASS</param-name>
<param-value>com.jiguang.report.utility.filename.JpmsFilenameGenerator</param-value>
</context-param>
最后修改一下FramesetFragment这个类的doPreService方法,有一段设置文件编码的,应该是这样的:
response.addHeader("Content-Disposition","attachment;filename=" + filedisplay);
把这个去掉,改成下面的代码:
String filename = ParameterAccessor.getExportFilename( new BirtContext( request, response ), format, emitterId );
String filedisplay = URLEncoder.encode(filename,"UTF-8");
response.setHeader( "Content-Disposition", //$NON-NLS-1$
ParameterAccessor.htmlHeaderValueEncode( openType )
+ "; filename=\"" //$NON-NLS-1$
+ ParameterAccessor.htmlHeaderValueEncode( filedisplay )
+ "\"" );
ok,应该就这些,调用的时候通过在调用报表的url上拼接参数__exportName="这是中文报表 "就ok了。

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|birt家园    

GMT+8, 2017-10-20 07:44 , Processed in 0.190812 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表