怎么把上传的excel表内容导入到数据库
2015-11-25 11:56
417 查看
字段要对应,此处只能操作后缀为xls的excel文件
/**
* 导入ventrue附件二
*
* @param r
* @return
* @throws BiffException
* @throws IOException
*/
public static ListExcel excleupload4(Resource r, int num) throws BiffException, IOException {
ListExcel list = new ListExcel();
List<LoanOriginationVentureTwo> listtwo = new ArrayList<LoanOriginationVentureTwo>();
List<LoanOriginationVentureFour> listfour = new ArrayList<LoanOriginationVentureFour>();
String filePath = r.getResourcePath();
// String filePath = "F:/2015年科技信贷专项征集通知(整理20150710)/创投/附件二 投资明细表.xls";
if (!filePath.endsWith(".xls")) {
return null;
}
Workbook rwb = Workbook.getWorkbook(new File(filePath));
Sheet rs = rwb.getSheet(0);
String unitsName = rs.getCell(0, 0).getContents();
if (num == 1) {
if (unitsName.length() > 6) {
unitsName = unitsName.substring(7);
} else {
unitsName = "";
}
}
if (num == 2) {
if (unitsName.length() > 8) {
unitsName = unitsName.substring(9);
} else {
unitsName = "";
}
}
StringBuffer sb = new StringBuffer();
int rows = rs.getRows();
for (int i = 1; i < 7; i++) {
sb.append(rs.getCell(i, rows - 1) + ",");
}
for (int i = 3; i < rows - 1; i++) {
int j = 0;
String id = rs.getCell(j++, i).getContents();// 默认最左边编号也算一列
String enterName = rs.getCell(j++, i).getContents();
String foundTime = rs.getCell(j++, i).getContents();
String industry = rs.getCell(j++, i).getContents();
String investmentAmount = rs.getCell(j++, i).getContents();
String finanTime = rs.getCell(j++, i).getContents();
String remarks = rs.getCell(j++, i).getContents();
if (enterName != null && !enterName.equals("")) {
if (num == 1) {
listtwo.add(new LoanOriginationVentureTwo(unitsName, enterName, foundTime, industry,
investmentAmount, finanTime, remarks, sb.toString()));
}
if (num == 2) {
listfour.add(new LoanOriginationVentureFour(unitsName, enterName, foundTime, industry,
investmentAmount, finanTime, remarks, sb.toString()));
}
}
}
list.setListloanOriginationVentureTwo(listtwo);
list.setListloanOriginationVentureFour(listfour);
return list;
}
/**
* 导入ventrue附件二
*
* @param r
* @return
* @throws BiffException
* @throws IOException
*/
public static ListExcel excleupload4(Resource r, int num) throws BiffException, IOException {
ListExcel list = new ListExcel();
List<LoanOriginationVentureTwo> listtwo = new ArrayList<LoanOriginationVentureTwo>();
List<LoanOriginationVentureFour> listfour = new ArrayList<LoanOriginationVentureFour>();
String filePath = r.getResourcePath();
// String filePath = "F:/2015年科技信贷专项征集通知(整理20150710)/创投/附件二 投资明细表.xls";
if (!filePath.endsWith(".xls")) {
return null;
}
Workbook rwb = Workbook.getWorkbook(new File(filePath));
Sheet rs = rwb.getSheet(0);
String unitsName = rs.getCell(0, 0).getContents();
if (num == 1) {
if (unitsName.length() > 6) {
unitsName = unitsName.substring(7);
} else {
unitsName = "";
}
}
if (num == 2) {
if (unitsName.length() > 8) {
unitsName = unitsName.substring(9);
} else {
unitsName = "";
}
}
StringBuffer sb = new StringBuffer();
int rows = rs.getRows();
for (int i = 1; i < 7; i++) {
sb.append(rs.getCell(i, rows - 1) + ",");
}
for (int i = 3; i < rows - 1; i++) {
int j = 0;
String id = rs.getCell(j++, i).getContents();// 默认最左边编号也算一列
String enterName = rs.getCell(j++, i).getContents();
String foundTime = rs.getCell(j++, i).getContents();
String industry = rs.getCell(j++, i).getContents();
String investmentAmount = rs.getCell(j++, i).getContents();
String finanTime = rs.getCell(j++, i).getContents();
String remarks = rs.getCell(j++, i).getContents();
if (enterName != null && !enterName.equals("")) {
if (num == 1) {
listtwo.add(new LoanOriginationVentureTwo(unitsName, enterName, foundTime, industry,
investmentAmount, finanTime, remarks, sb.toString()));
}
if (num == 2) {
listfour.add(new LoanOriginationVentureFour(unitsName, enterName, foundTime, industry,
investmentAmount, finanTime, remarks, sb.toString()));
}
}
}
list.setListloanOriginationVentureTwo(listtwo);
list.setListloanOriginationVentureFour(listfour);
return list;
}
相关文章推荐
- mysql中Table is read only的解决方法小结
- mongoDB配置及服务启动制作
- MongoDB中的一个分组统计的查询(Group ... Distinct)
- 用Redis实现分布式锁 与 实现任务队列
- MySqlhq语句拼接时间查询
- MYSQL SSL
- Oracle查看当天创建的所有表
- PowerDesigner数据库建模
- 详解SQL Server数据修复命令DBCC的使用
- 非常不错的MySQL优化的8条经验
- ORACLE 创建自增序列生成流水号
- MySQL 优化之 ICP (index condition pushdown:索引条件下推)
- MySQL中利用索引对数据进行排序的基础教程
- mysql 对取当前日期周一和周日语句的详细解析
- jedispool 连 redis 高并发卡死 解决方案
- group by 多个条件进行分组
- Windows 下 MySQL 的配置创建mysql服务
- 页面上的复选框,然后保存到数据库,再从数据库取出来,看那个复选框被选中
- 快速学习MySQL索引的入门超级教程
- 利用索引和表扫描原理优化查询SQL语句