excel 导入功能
一:示例代码
//InputStream fis = new FileInputStream(tomcaturl+this.awardTask.getFileRoute());
//可以通过上述方式获得InputStream
private List<XueBaQuestionEntity> GetAllImportQuestion(InputStream inputstream) {
// POIFSFileSystem fs;
// HSSFWorkbook wb;
// HSSFSheet sheet;
// HSSFRow row;
// HSSF只支持excel2003
List<XueBaQuestionEntity> questionList = new ArrayList<XueBaQuestionEntity>();
List<XueBaOptionEntity> optionList;
XueBaQuestionEntity question = null; try{
// fs = new POIFSFileSystem(inputstream);
// wb = new HSSFWorkbook(fs);
Workbook wb = WorkbookFactory.create(inputstream);
/** 遍历sheet **/
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
/** 获得当前sheet **/
Sheet sheet = wb.getSheetAt(i);
int num = 1;
for (int j = 1; j < sheet.getPhysicalNumberOfRows() ; j++) {
num++;
try{
question = new XueBaQuestionEntity();
optionList = new ArrayList<XueBaOptionEntity>();
/** 获得当前行情 **/
Row row = sheet.getRow(j);
if(row != null){
String qContent = getCellFormatValue(row.getCell(0)).trim();
String aOption = getCellFormatValue(row.getCell(1)).trim();
//题目或A选项为空就不保存
if(StringUtil.isEmpty(qContent) || StringUtil.isEmpty(aOption)){
logger.info("题库第" + num + "行题库或A选项为空,未保存");
continue;
}
String bOption = getCellFormatValue(row.getCell(2)).trim();
String cOption = getCellFormatValue(row.getCell(3)).trim();
String dOption = getCellFormatValue(row.getCell(4)).trim();
String eOption = getCellFormatValue(row.getCell(5)).trim();
String answer = getCellFormatValue(row.getCell(6)).trim(); System.out.println("qcontent:"+qContent);
/* 赋值问题实体 */
question.setContent(qContent);
if(answer.indexOf(",")>0){
question.setType(1);
}else{
question.setType(0);
}
question.setAnswer(answer);
//赋值选项实体
if (StringUtil.isNotEmpty(aOption)) {
XueBaOptionEntity aOptionEntity = new XueBaOptionEntity();
aOptionEntity = DealOption(aOptionEntity,aOption);
optionList.add(aOptionEntity);
}
if (StringUtil.isNotEmpty(bOption)) {
XueBaOptionEntity bOptionEntity = new XueBaOptionEntity();
bOptionEntity = DealOption(bOptionEntity,bOption);
optionList.add(bOptionEntity);
}
if (StringUtil.isNotEmpty(cOption)) {
XueBaOptionEntity cOptionEntity = new XueBaOptionEntity();
cOptionEntity = DealOption(cOptionEntity,cOption);
optionList.add(cOptionEntity);
}
if (StringUtil.isNotEmpty(dOption)) {
XueBaOptionEntity dOptionEntity = new XueBaOptionEntity();
dOptionEntity = DealOption(dOptionEntity,dOption);
optionList.add(dOptionEntity);
}
if (StringUtil.isNotEmpty(eOption)) {
XueBaOptionEntity eOptionEntity = new XueBaOptionEntity();
eOptionEntity = DealOption(eOptionEntity,eOption);
optionList.add(eOptionEntity);
} question.setXueBaOptionList(optionList);
questionList.add(question);
}
}catch (Exception e) {
e.printStackTrace();
logger.info("题库第" + num + "行解析异常");
}
}
}
}catch (Exception e) {
e.printStackTrace();
}
return questionList;
} private XueBaOptionEntity DealOption(XueBaOptionEntity optionEntity,
String option) {
int start = option.indexOf("、");
// System.out.println("option:"+option+" start:"+start);
String optionTitle = option.substring(0, start);
String optionContent = option.substring(start+1);
optionEntity.setTitle(optionTitle);
optionEntity.setContent(optionContent);
return optionEntity;
} private String getCellFormatValue(Cell cell) {
String cellvalue = "";
if (cell != null) {
// 判断当前Cell的Type
switch (cell.getCellType()) {
// 如果当前Cell的Type为NUMERIC
case Cell.CELL_TYPE_NUMERIC:{
BigDecimal big = new BigDecimal(cell.getNumericCellValue());
cellvalue = big.toString();
break;
}
case Cell.CELL_TYPE_FORMULA: {
BigDecimal bigula = new BigDecimal(cell
.getCachedFormulaResultType());
cellvalue = bigula.toString();
break;
}
// 如果当前Cell的Type为STRING
case Cell.CELL_TYPE_STRING:
// 取得当前的Cell字符串
cellvalue = cell.getRichStringCellValue().getString();
break;
// 默认的Cell值
default:
cellvalue = " ";
}
} else {
cellvalue = "";
}
return cellvalue;
}
excel 导入功能的更多相关文章
- 解析大型.NET ERP系统 设计通用Microsoft Excel导入功能
做企业管理软件很难避免与Microsoft Excel打交道,常常是软件做好了,客户要求说再做一个Excel导入功能.导入Excel数据的功能的难度不大,从Excel列数据栏位的取值,验证值,再导入到 ...
- java利用jxl实现Excel导入功能
本次项目实践基于Spring+SpringMvc+MyBatis框架,简单实现了Excel模板导出.和Excel批量导入的功能.实现过程如下:. 1.maven导入所需jar包 <depende ...
- 后端Springboot前端VUE实现Excel导入功能
功能描述:做的是物联网的项目,Excel导入实现的功能是将Excel中的数据批量的导入AEP系统,再导入我们系统中.目前已经完成该功能,前端还会添加进度条优化.对于导入导出功能,推荐这个Git:htt ...
- Excel导入功能
一:前端 <t:dgToolBar title="Excel题库导入" icon="icon-search" onclick="question ...
- Java中Excel导入功能实现、excel导入公共方法_POI -
这是一个思路希望能帮助到大家:如果大家有更好的解决方法希望分享出来 公司导入是这样做的 每个到导入的地方 @Override public List<DataImportMessage> ...
- Excel导入功能(Ajaxfileupload)
前言: 前端采用Easyui+Ajaxfileupload实现 后端采用springmvc框架,其中把解析xml封装成了一个jar包,直接调用即可 准备: 前端需要导入(easyui导入js省略,自行 ...
- php Excel 导入功能
下载excel类地址 https://pan.baidu.com/s/19MqAHUn4RyZ5HEAChyC0jg 密码:mn58 本人用的thinkcmf框架 把类文件放在框架的类文件里面,下面 ...
- Java Controller下兼容xls和xlsx且可识别合并单元格的excel导入功能
1.工具类,读取单元格数据的时候,如果当前单元格是合并单元格,会自动读取合并单元格的值 package com.shjh.core.util; import java.io.IOException; ...
- React + Antd开发模式下的Excel导入功能
具体js如下,配合的是antd里面的upload组件,使用的是xlsx插件 npm : npm install xlsx 插件链接: https://github.com/SheetJS/sheet ...
随机推荐
- CSAPP缓冲区溢出攻击实验(上)
CSAPP缓冲区溢出攻击实验(上) 下载实验工具.最新的讲义在这. 网上能找到的实验材料有些旧了,有的地方跟最新的handout对不上.只是没有关系,大体上仅仅是程序名(sendstring)或者參数 ...
- USACO prefix TrieTree + DP
/* ID:kevin_s1 PROG:prefix LANG:C++ */ #include <iostream> #include <cstdio> #include &l ...
- Expectation Maximization and GMM
Jensen不等式 Jensen不等式给出了积分的凸函数值必定大于凸函数(convex)的积分值的定理.在凸函数曲线上的任意两点间连接一条线段,那么线段会位于曲线之上,这就是将Jensen不等式应用到 ...
- Linux内核--网络栈实现分析(二)--数据包的传递过程--转
转载地址http://blog.csdn.net/yming0221/article/details/7492423 作者:闫明 本文分析基于Linux Kernel 1.2.13 注:标题中的”(上 ...
- 小白日记39:kali渗透测试之Web渗透-SQL手工注入(一)-检测方法
SQL手工注入(一) SQL注入:通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.[SQL注入原理] ##服务端程序将用户输入参数作为查询 ...
- JavaFX(二)自定义窗口标题栏
1.问题场景 PC客户端登录界面仿QQ,上边显示图片,下边显示输入框和登录按钮.而JavaFX默认的窗口,不满足需求. 2.解决思路 隐藏窗口默认的标题栏,使用创建label对象,使用css将按钮图片 ...
- 关于错位动画的练习,原生js编写
最近在网上看到一个关于错位动画的文章,感觉非常有趣,便自己练习了一下,文章连接:http://www.w3cplus.com/animation/staggering-animations.html ...
- DataTables warning (table id = 'myTable'): Requested unknown parameter '0' from the data source for row 0
第一种方式:不用在js里设置列Html: <table id="myTable"> <thead> <tr> <th>Title-1 ...
- jQuery数组处理
1. $.each(array, [callback]) 遍历[常用] 解释: 1.不同于例遍 jQuery 对象的 $().each() 方法,此方法可用于例遍任何对象(不仅仅是数组哦~). 2.回 ...
- MediaPlayer简单使用,绑定surfaceView实现播放视频的功能
转载自 Android MediaPlayer使用方法简单介绍 播放音频 android中播放音频可以使用MediaPlayer类来实现,一下是它的一些方法: 方法名 功能描述 setDataSour ...