后台批量导出Excel的问题

后台批量导出Excel-  http://help.finereport.com/doc-view-738.html
根据这上边的代码自己写了个java。。本地直接运行java测试成功。
把class文件放到图片所示的地方。。
然后自定义函数里边写一个java调用这个函数。如图所示

然后在帆软里边调用这个自定义函数,调用时tomcat和帆软后台都没报错。。返回值提示成功。。文件也生成,但是帆软的插件就崩溃了。。
求大神帮帮忙
java代码
  1. package com.fr.io.e;      
  2.       
  3. import java.io.BufferedReader;      
  4. import java.io.File;      
  5. import java.io.FileInputStream;      
  6. import java.io.FileOutputStream;      
  7. import java.io.InputStreamReader;      
  8. import java.io.OutputStream;      
  9. import java.util.Arrays;      
  10. import com.fr.base.FRContext;      
  11. import com.fr.general.ModuleContext;
  12. import com.fr.dav.LocalEnv;
  13. import com.fr.io.TemplateWorkBookIO;
  14. import com.fr.io.exporter.ExcelExporter;  
  15. import com.fr.main.TemplateWorkBook;   
  16. import com.fr.main.workbook.ResultWorkBook;
  17. import com.fr.report.module.EngineModule;
  18. import com.fr.stable.StableUtils;  
  19. import com.fr.stable.WriteActor;
  20. import com.sun.scenario.effect.Bloom;
  21.      
  22.       
  23. public class ExportBatch {   
  24.         static String envpath = "/opt/apache-tomcat-8.5.16/webapps/WebReport/WEB-INF";
  25.         static boolean falg = true;
  26.         /*
  27.         public static void main(String[] args) {      
  28.                 ExportBatch a = new ExportBatch();
  29.                 boolean f = a.xls("报表名称","报表路径",new File("txt文件"),"C");
  30.                 System.out.println(f);
  31.         }
  32.         */
  33.         public ExportBatch(){
  34.                
  35.         }
  36.         public ExportBatch(Object o){
  37.                
  38.         }
  39.         public boolean xls(String cptName,String cptPath,File parafile,String filePath){
  40.                 falg = true;
  41.                 //ExportBatch.export("报表名称","报表路径",new File("txt文件"),"C");
  42.                 ExportBatch.export(cptName,cptPath,parafile,filePath);
  43.                 return falg;
  44.         }
  45.         /*
  46.          * cptName--cpt的报表名称
  47.          * cptPath--cpt的报表路径
  48.          * parafile--用于传参数用的txt文件的存放路径
  49.          * filePath--盘符路径如C、D、E
  50.          */
  51.         public static void export(String cptName,String cptPath,File parafile,String filePath){
  52.                 try {      
  53.                         // 定义报表运行环境,用于执行报表           
  54.                         //static String envpath = "/opt/apache-tomcat-8.5.16/webapps/WebReport/WEB-INF";
  55.                         FRContext.setCurrentEnv(new LocalEnv(envpath));   
  56.                         ModuleContext.startModule(EngineModule.class.getName());   
  57.                         // 读取环境下的模板文件   
  58.                         TemplateWorkBook workbook = TemplateWorkBookIO.readTemplateWorkBook(FRContext.getCurrentEnv(),cptPath);   
  59.                         //用参数替换 "doc\\Primary\\DetailReport\\Details.cpt"
  60.                         // 读取用于保存的参数值的txt文件   
  61.                         //File parafile = new File(envpath + "\\para.txt");  //用参数替换文件路径  
  62.                         FileInputStream fileinputstream;   
  63.                         fileinputstream = new FileInputStream(parafile);   
  64.                         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileinputstream));   
  65.                         // 定义保存参数的map,用于执行报表   
  66.                         java.util.Map paramap = new java.util.HashMap();   
  67.                         /*  
  68.                          * 遍历参数值所在TXT文件,TXT文件中参数保存形式为 para1,para2 江苏,陈羽 江苏,安娜 首先取出第一行保存参数名称  
  69.                          * 遍历每个参数组合,如para1=江苏、para2=陈羽,根据参数执行模板,并将结果导出excel excel文件名为名称+导出编号  
  70.                          */   
  71.                         // 读第一行,保存参数名称   
  72.                         String lineText = bufferedReader.readLine();   
  73.                         lineText = lineText.trim();   
  74.                         String[] paraname = StableUtils.splitString(lineText, ",");   
  75.                         System.out.println(Arrays.toString(paraname));   
  76.                         // 遍历每个参数组合,执行模板,导出结果   
  77.                         int number = 0;   
  78.                         while ((lineText = bufferedReader.readLine()) != null) {   
  79.                                 lineText = lineText.trim();   
  80.                                 String[] paravalue = StableUtils.splitString(lineText, ",");   
  81.                                 for (int j = 0; j < paravalue.length; j++) {   
  82.                                         paramap.put(paraname[j], paravalue[j]);   
  83.                                 }   
  84.                                 ResultWorkBook result = workbook.execute(paramap,new WriteActor());  
  85.                                 OutputStream outputstream = new FileOutputStream(new File(filePath+":\\"+ cptName + lineText + ".xls"));   
  86.                                 ExcelExporter excelexporter = new ExcelExporter();   
  87.                                 excelexporter.export(outputstream, result);   
  88.                                 // 最后要清空一下参数map,用于下次计算   
  89.                                 paramap.clear();   
  90.                                 number++;   
  91.                                 outputstream.close();  
  92.                         }
  93.                         ModuleContext.stopModules();
  94.                         System.out.print("try");
  95.                 } catch (Exception e) {
  96.                         //e.printStackTrace();
  97.                         falg = false;
  98.                         System.out.println("catch");
  99.                 }
  100.                      
  101.         }
  102. }
复制代码
自定义函数的代码
  1. package com.fr.test;  

  2. import java.io.File;  
  3. import com.fr.io.e.ExportBatch;
  4. import com.fr.script.AbstractFunction;  
  5.   
  6. public class CSUM extends AbstractFunction {  
  7.     public Object run(Object[] args) {  
  8.                 ExportBatch a = new ExportBatch();
  9.                 boolean f = a.xls("AA","doc/Primary/DetailReport/Details.cpt",new File("/opt/apache-tomcat-8.5.16/webapps/WebReport/a.txt"),"D");
  10.                 //System.out.println(f);
  11.                 return f;  
  12.     }  
  13. }  
复制代码


编辑于 2018-1-12 10:01  
编辑于 2018-1-12 10:02  
FineReportMOMO_KANA 发布于 2018-1-11 18:54
悬赏:5 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共7回答
最佳回答
0
MOMO_KANA发布于2018-1-11 18:54(编辑于 2023-9-6 09:34)
555
  • 捉迷藏小样 捉迷藏小样 大佬,请问这个 问题要怎么解决啊,我现在也遇到这个问题了?
    回复
    2018-08-23 15:41 
  • 小小杯子 小小杯子 请问dalao 这个批量导出的是怎么做的 我的java文件写好之后 应该怎么使用呢
    回复
    2019-07-17 10:00 
最佳回答
0
MOMO_KANA发布于2018-1-12 09:06(编辑于 2023-9-6 09:34)
555
最佳回答
0
风起了发布于2018-1-12 10:12(编辑于 2023-9-6 09:34)
555
最佳回答
0
MOMO_KANA发布于2018-1-12 11:01(编辑于 2023-9-6 09:34)
555
最佳回答
0
郁金香发布于2018-1-12 11:58(编辑于 2023-9-6 09:34)
555
最佳回答
0
捉迷藏小样发布于2018-8-23 15:42(编辑于 2023-9-6 09:34)
555
  • 1关注人数
  • 1336浏览人数
  • 最后回答于:2018-8-23 15:42
    活动推荐 更多
    热门课程 更多
    返回顶部