由于行式填报在导入excel的数据量比较大的时候,页面加载数据会很慢,在这种情况下可以采取后台直接导入数据库的方法,实例如下:

package example;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.text.SimpleDateFormat;
import java.util.Locale;

import com.runqian.base4.resources.FormatUtils;
import com.runqian.report4.ide.ExcelImporter;
import com.runqian.report4.input.DataSaver;
import com.runqian.report4.input.RowReportSaver;
import com.runqian.report4.model.ReportDefine;
import com.runqian.report4.model.engine.ExtCellSet;
import com.runqian.report4.model.engine2.RowReport;
import com.runqian.report4.usermodel.Area;
import com.runqian.report4.usermodel.Context;
import com.runqian.report4.usermodel.DataSourceConfig;
import com.runqian.report4.usermodel.Engine;
import com.runqian.report4.usermodel.INormalCell;
import com.runqian.report4.usermodel.IReport;
import com.runqian.report4.usermodel.input.InputProperty;
import com.runqian.report4.util.ReportUtils;

public class DateFromExcel2 {

Context cxt = null;

public void saveFromExcel(String reportFile, String excelFile, int sheetNum)
throws Exception {
IReport report = calcReport(reportFile); //计算出填报表
RowReport rr = ( RowReport ) report;
String did = rr.getDetailID( 2 ); //第二行是扩展主行
//System.out.println(”did–>”+did);
SimpleDateFormat dateF = new SimpleDateFormat( FormatUtils.getDateFormat( Locale.getDefault() ) );
SimpleDateFormat timeF = new SimpleDateFormat( FormatUtils.getTimeFormat( Locale.getDefault() ) );
SimpleDateFormat datetimeF = new SimpleDateFormat( FormatUtils.getDatetimeFormat( Locale.getDefault() ) );
//System.out.println(”datef->”+dateF);
//System.out.println(”timeF->”+timeF);
//System.out.println(”datetimeF->”+datetimeF);
RowReportSaver rowSaver = new RowReportSaver( rr, null, cxt );
IReport excelReport = excelToReport(excelFile,sheetNum);
//int rows = excelReport.getRowCount();
//short cols = excelReport.getColCount();
//if(rows>report.getRowCount()) rows = report.getRowCount();
//if(cols>report.getColCount()) cols = report.getColCount();
for(int i=2;i<=excelReport.getRowCount();i++){ 逐行逐列把excel数据写入填报表
Area area = rr.insertDetail( did );
for(int j=1;j<=excelReport.getColCount();j++){
INormalCell iExcelCell=excelReport.getCell(i, (short)j); //取得excel单元格
//System.out.println(”iExcelCell.getValue()–>”+iExcelCell.getValue());

//System.out.println(”area.getBeginRow()–>”+area.getBeginRow());
//System.out.println(”i->”+i);
//System.out.println(”(short)j->”+(short)j);
if( iExcelCell == null ) continue;
String svalue = “”;
Object value = iExcelCell.getValue();
if( value != null ) svalue = value.toString();
System.out.println(”svale->”+svalue);
rowSaver.setCellInputValue( area.getBeginRow(), (short)j, svalue, dateF, timeF, datetimeF );
}
}
//ReportUtils.write(”c:/qq.raq”,report);
rowSaver.save();
}

private IReport calcReport(String reportFile) throws Exception {
ReportDefine rd = (ReportDefine) ReportUtils.read(reportFile);
cxt = new Context();

Connection connection = null;
try {
Driver driver = (Driver) Class.forName(”org.hsqldb.jdbcDriver”)
.newInstance();
DriverManager.registerDriver(driver);
connection = DriverManager.getConnection(
“jdbc:hsqldb:hsql://localhost/runqianDB”, “sa”, “”);
} catch (Exception e) {
e.printStackTrace();
}

// 设置数据源,动态改变连接参数
cxt.setDefDataSourceName(”demo”);
// 设置数据连接,也可以设置连接池工厂,如cxt.setConnectionFactory(sourceName,connectionFactory)
// 其中connectionFactory这个类必须implements IConnectionFactory,并且实现他的public
// java.sql.Connection getConnection() throws Exception 方法
cxt.setConnection(”demo”, connection);
DataSourceConfig dsoc = new DataSourceConfig(2, true, “GBK”, “GBK”,
false);
cxt.setDataSourceConfig(”demo”, dsoc);

Engine engine = new Engine(rd, cxt);
IReport iReport = engine.calc();
return iReport;

} private IReport excelToReport(String excelFile, int sheetNum)
throws Exception {
ExcelImporter ei = new ExcelImporter(excelFile);
return ei.getReport(sheetNum);
}

public static void main(String[] args){
String license = “D:\\software\\tomcat\\tomcat5.0.28\\webapps\\report4\\WEB-INF\\2009-03-31V4.0Windows.lic”;
String reportFile = “D:\\software\\tomcat\\tomcat5.0.28\\webapps\\report4\\reportFiles\\newapi\\input.raq”;
String excelFile = “D:\\software\\tomcat\\tomcat5.0.28\\webapps\\report4\\reportFiles\\newapi\\input.xls”;
int sheetNum = 0;
DateFromExcel2 dexcel = new DateFromExcel2();
ExtCellSet.setLicenseFileName( license );
try {
dexcel.saveFromExcel(reportFile,excelFile,sheetNum);
} catch (Exception ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
}

}

然后在前台页面上设置一个按钮来调用这个后台类,就可以实现行式填报表导入excel直接保存数据入库的功能了.

行式填报表导入excel数据直接入库相关推荐

  1. 行式填报表轻松搞定流水号

    在各式各样的报表业务需求中,有这样一类,不仅要对数据进行统计呈现,还要基于这些数据做增.删.改的操作并与数据库进行交互.这种情况下,无论从数据库统一管理还是数据合法性角度考虑,都难免需要进行诸如自动计 ...

  2. 如何利用API实现行式报表后台导入excel数据入库

     润乾报表提供了excel导入页面后入库的功能,丰富了用户导入excel的方式.对于普通填报表,润乾报表提供了直接后台入库和导入页面入库的方式,那么在行式填报表中,如何实现后台导入excel入库呢 ...

  3. 帆软填报--行式填报报表

    帆软填报 准备 下载帆软设计器,自己注册账号,获取激活码 定义数据连接,分为测试库和生产库两个 配置帆软填报MySQL库测试环境 测试 帆软库建表 登录测试开发工作目录 为模板指定数据集 为模板添加数 ...

  4. php导入excel先检查,php 如何在导入Excel数据时检查Mysql数据库内容是否存在,避免重复录入?:怎么样筛选excel表格重复的数据库...

    php 如何在导入Excel数据时检查Mysql数据库内容是否存在,避免重复录入? 如果不想每询一次以提前做一个统询 $sql=mysql_query("select distinct Co ...

  5. python导入excel数据-如何把python中的数据导入excel

    python将数据导入excel的方法:1.在python官网下载xlrd第三方库:2.利用xlrd中的open_workbook函数读入excel文件,即可在python中导入excel数据. 一. ...

  6. php 导入表格数据,PHPExcel 导入Excel数据的方法

    这篇文章主要介绍了关于PHPExcel 导入Excel数据的方法,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 一:使用composer下载 phpoffice/phpexcel 或者 ...

  7. mysql导入excel表_mysql怎么导入excel数据?

    mysql导入excel数据的步骤: 1.第一步我们得到了一个excel表,里面有很多需要我们导入的数据. 2.删除第1行"准考证号""XXX"....只保留我 ...

  8. MySQL批量导入Excel数据

    1.确定需要导入数据的表名称以及字段,然后在新建的Excel表中,按照表字段正确排序:(注:(Excel文件的名称最好和数据库的名称一致,sheet表的名字最好和表名称一致,方便需要导入多张表数据时一 ...

  9. HSSFWorkbook下载xls表格模板及导入excel数据

    效果图:(有列置灰.隐藏.下拉列表功能) 下载excel模板代码: private AjaxResult myBatchImportTemplateSelect(List<ProjectTask ...

最新文章

  1. CMake结合PCL库学习(2)
  2. 大数据+人工智能正以八种方式撼动商界
  3. oracle隐式转换函数,隐式数据类型转换案例一则
  4. ElementUI 组件库 md-loader 的解析和优化
  5. 一线Java架构师概括互联网公司的标准Java技术架构
  6. InitGoogleLogging坑爹
  7. script标签的使用,从零开始
  8. PickerView
  9. 2021年好看高考倒计时源码
  10. 微商分销代理商城源码带代理等级和升级条件 thinkphp框架
  11. Unity中实现表格功能
  12. windows server 2008 关机后安装自动更新,反复启动,不能进入系统
  13. 《大学英语翻译》课程相关复习笔记
  14. AAAI-19录用论文
  15. iosSelect插件 H5中实现iOS的select下拉联动效果
  16. C++编程-牛客网-雀魂启动
  17. oracle 密码解锁
  18. gnuplot 两点画线
  19. java.lang.Short常用方法
  20. 20180402-C · US Tuition Costs · ggplot2, 地图 热力图 · R 语言数据可视化 案例 源码

热门文章

  1. input输入框只读的几种方式
  2. 你打算买新版 Mac Book 吗?- 鸟语花香[01]
  3. javascript实现评论内容展开、收起(默认收起)
  4. 太翼健康携手绿城,共建未来社区健康服务体系
  5. python百度网盘自动同步_bypy-让你的猫盘随时同步文件至百度云 - 矿渣社区 - 猫盘 - 硬件专区 - Powered by Discuz!...
  6. 【JS】用户可选择确定或取消的提示框
  7. LintCode 92: Backpack (经典背包DP题)
  8. python结构体排序
  9. std::set/std::map 的几个为什么
  10. Modbus-RTU通讯协议中CRC校验码的计算步骤及算法代码