您的位置:首页 > 数据库

怎么把上传的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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: