当前位置: 代码迷 >> Java Web开发 >> ireport导出excel乱码,该怎么解决
  详细解决方案

ireport导出excel乱码,该怎么解决

热度:7298   发布时间:2013-02-25 21:06:53.0
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 
  相关解决方案