birt 修改导出的文件名分两种实现方法,
第一种:修改 web.xml 中 配置的 BIRT_FILENAME_GENERATOR_CLASS
我是用的 TimestampFilenameGenerator ,那我们就直接修改它的getFilename方法.
package org.eclipse.birt.report.utility.filename;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
public class TimestampFilenameGenerator
implements IFilenameGenerator
{
private static final String DEFAULT_DATE_PATTERN = "yyyyMMdd-HHmmss";
public String datePattern;
public TimestampFilenameGenerator()
{
this(null);
}
public TimestampFilenameGenerator(String datePattern)
{
if (datePattern == null) {
datePattern = "yyyyMMdd-HHmmss";
}
this.datePattern = datePattern;
}
public String getFilename(String baseName, String fileExtension, String outputType, Map options)
{
DateFormat dateFormatter = new SimpleDateFormat(this.datePattern);
if (fileExtension == null) {
fileExtension = "";
}
return baseName + "_" + dateFormatter.format(new Date()) + "." + fileExtension;
}
}
第二种: 就是自己实现IFilenameGenerator 接口,并配置 BIRT_FILENAME_GENERATOR_CLASS
@Override
public String getFilename(String baseName, String fileExtension, String outputType, Map options) {
try {
//报表模板名称判断
if (baseName.equals("billOfSales")) {
//获取报表对象
BaseAttributeBean attrBean = (BaseAttributeBean) options.get("viewerAttributesBean");
//报表参数名称获取参数
Object a = attrBean.getParameters().get("NewParameter");
baseName = new String((a + "出货单").getBytes("utf-8"), "iso-8859-1");
}
} catch (UnsupportedEncodingException e) {
baseName = "未命名";
}
return baseName + "." + fileExtension;
}