ireport导出excel乱码
报表里的内容都是英文的,因为是加拿大的项目,现在我不理解我导出excel为什么乱码那,大家帮忙看看
public String branchExcelReport(List list) {
JasperPrint jasperPrintArr=null;
ArrayList jasperPrintList = new ArrayList();
HttpServletResponse resp=null;
JasperReport report;
Map map=new HashMap();
String realPath = "";
resp = (HttpServletResponse)ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_RESPONSE);
realPath =ServletActionContext.getServletContext().getRealPath(
"/report/template/Branch.jasper");
JRDataSource dataSource = new JRBeanCollectionDataSource(list);
try {
report = (JasperReport)JRLoader.loadObject(realPath);
jasperPrintArr = JasperFillManager.fillReport (report, map, dataSource);
jasperPrintList.add(jasperPrintArr);
//设定输出格式
FileBufferedOutputStream fbos = new FileBufferedOutputStream();
// 使用JRPdfExproter导出器导出pdf
JRPdfExporter exporter = new JRPdfExporter();
// 设置JasperPrintList
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fbos);
exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporter.exportReport();
resp.reset();
resp.setContentType("application/vnd.ms-excel;charset=UTF-8");
resp.setCharacterEncoding("UTF-8");
resp.setContentLength(fbos.size());
resp.setHeader("Content-Disposition", "attachment; filename=BRANCH.xls");
ServletOutputStream ouputStream = resp.getOutputStream();
try
{
fbos.writeData(ouputStream);
fbos.dispose();
ouputStream.flush();
}
finally
{
if (ouputStream != null)
{
try
{
fbos.close();
ouputStream.close();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
sheet.addCell(new Label(i, 0, titles[i]));
}
if(list != null && list.size()>0){
Iterator i = list.iterator();
int line = 1;
while (i.hasNext()) {
JWJX_JXdajbxx tsc = (JWJX_JXdajbxx) i.next();
for (int j = 0; j < properties.length; j++) {
Object value = PropertyUtils.getSimpleProperty(tsc,properties[j]);
value = value != null ? value : "";
if(properties[j].equals("wjlx")){
if(wjlxdms != null){
for(int a=0;a<wjlxdms.size();a++){
DM_wjlxdm dmwjlx = (DM_wjlxdm)wjlxdms.get(a);
if(tsc.getWjlx() .equals(dmwjlx.getWjlxdmid()) ){
value = dmwjlx.getMc();
}
}
}
}
if(properties[j].equals("bgqx")){
if(bgqxs != null){
for(int a=0;a<bgqxs.size();a++){
DM_bgqx dmbgqx = (DM_bgqx)bgqxs.get(a);
if(tsc.getBgqx().equals(dmbgqx.getBgqxid()) ){
value = dmbgqx.getMc();
}
}
}
}
sheet.addCell(new Label(j, line, value.toString()));
}
line++;
}
}
// 将组装好的Excel文件以流的格式输出到客户端
book.write();
book.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
[解决办法]
在设计模版的时候有没有编码选择啊!好久没用ireport都忘了。