集智平台报表自动导入excel

润乾报表可以实现在设计器中把excel文件导入成raq文件,但是有些客户希望在后台通过代码自动把excel导成raq文件,然后再在其他的地方使用导成的raq文件。这样一来,设计器中的导入excel功能就不能满足客户的需求了,需要自己写API代码来实现客户的需求。

需求的实现思路为:通过润乾API中的ExcelImporter类里面的saveTo ()方法把excel导成raq到本地路径。

实现API自动导入excel成raq的代码如下:

package com.zhengzhong.practise;

 

import java.io.OutputStream;

 

import com.runqian.report4.ide.ExcelImporter;

import com.runqian.report4.model.ReportDefine;

import com.runqian.report4.util.ReportUtils;

 

public class ImportExcel {

 

public void importer(String excel,String raq){

String[] str = null;

ReportDefine[] rds = null;

 

try {

ExcelImporter excelimport = new ExcelImporter(excel);

str = excelimport.saveTo(raq);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

for(int i=0;i<str.length;i++){

try {

ReportDefine rd = (ReportDefine)ReportUtils.read(str[i]);

System.out.println(“ssssssssssssssss=”+str[i]);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

 

}

public static void main(String[] args) {

// TODO Auto-generated method stub

String excel = “F:/aa.xls”;

String raq = “F:/”;

ImportExcel ie = new ImportExcel();

ie.importer(excel, raq);

}

 

}

上面API代码中的importer(String excel,String raq)方法的作用是根据传进来的需要导入的excel路径和要导成的raq路径(excel为需要导入的excel路径,raq为要输出的raq的路径),执行上面的代码就可以看到指定的excel被导成raq到指定的路径中了,上面的代码支持多sheet的excel,多sheet的excel导成raq的时候raq的名字为:(excel名字+sheet名字).raq

本文标签: