Jasper report with excel data source

只愿长相守 提交于 2019-12-25 01:20:46

问题


I have created, using a jasper designer (not iReport but a plugin for eclipse), a report that uses an excel file as datasource.
the report works fine, in the designer, and read the data from the file without problems but after compiling the file to file.jasper and giving him the excel file's path nothing apears in the JasperViewer!
This is my code:

try{
      Map<String, Object> parameters = new HashMap<String, Object>();
      parameters.put("DataFile", "jasper_export.xls");
      JasperPrint jasperPrint = JasperFillManager.fillReport(new FileInputStream(new File("file.jasper")), parameters,conn);

      JasperViewer jv = new JasperViewer(jasperPrint, false);
      jv.setVisible(true);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

回答1:


SOLUTION:
This code woks perfect:

try{
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("param_name", paramValue);

    ExcelDataSource ds = new ExcelDataSource(JRLoader.getLocationInputStream(excelFilePath));
    String[] columnNames = new String[]{"id", "nom", "iden", "adress", "activity", "compta"};
    ds.setColumnNames(columnNames);
    JasperPrint jasperPrint = JasperFillManager.fillReport(new FileInputStream(new File(yourJasperFilePath)), parameters, ds);
    JasperPrintManager.printReport(jasperPrint, false);
   } catch (Exception ex) {
      ex.printStackTrace();

   }


来源:https://stackoverflow.com/questions/28025127/jasper-report-with-excel-data-source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!