数据库传输工具"/>
java 数据库传输工具
public boolean excelToAps(File file,String type ) throwsException {
System.out.println("paymentBo.excelToAps进入");try{
Workbook workbook=getWeebWork(type,file);
Sheet sheet= workbook.getSheetAt(0);
FormulaEvaluator evaluator=workbook.getCreationHelper().createFormulaEvaluator();int rownum = sheet.getLastRowNum();//获取总行数
int minRowIx =sheet.getFirstRowNum();int maxRowIx =sheet.getLastRowNum();
List list = new ArrayList(); //测试存放数据的list
List listPayment = new ArrayList();//将exl中的数据提取后存放的list
System.out.println("rownum:"+rownum+"minRowIx:"+minRowIx+",maxRowIx:"+maxRowIx);for (int rowIx = 1; rowIx <= maxRowIx; rowIx++) {
Row row=sheet.getRow(rowIx);
StringBuilder sb= newStringBuilder();short minColIx =row.getFirstCellNum();short maxColIx =row.getLastCellNum();
PaymentDataVo payvoDataVo=newPaymentDataVo();//System.out.println("minColIx:"+minColIx+"maxColIx:"+maxColIx );
System.out.print("第"+rowIx+"行数据:");for (short colIx = 0; colIx < maxColIx; colIx++) {
Cell cell= row.getCell(newInteger(colIx));
CellValue cellValue=evaluator.evaluate(cell);/******/DecimalFormat df= new DecimalFormat("######0.00");if(colIx == 0){//日期
String date =cellValue.getNumberValue()+"";
System.out.print(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(cell.getDateCellValue())+",");
payvoDataVo.setCreateTime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(cell.getDateCellValue()));
}else if(colIx== 1){//卡类
System.out.print((int)cellValue.getNumberValue()+",");
payvoDataVo.setPaymentId((int)cellValue.getNumberValue());
}else if(colIx == 2){//消费类型
System.out.print((int)cellValue.getNumberValue()+",");//payvoDataVo.setConsumprionId(cellValue.getNumberValue());
}else if(colIx == 3){//明细类型
System.out.print(cellValue.getStringValue()+",");
payvoDataVo.setDataType(cellValue.getStringValue());
}else if(colIx == 4){//消费简述
System.out.print(cellValue.getStringValue()+",");
payvoDataVo.setDataName(cellValue.getStringValue());
}else if(colIx == 5){//消费金额
System.out.print(df.format(cellValue.getNumberValue()));
payvoDataVo.setDataAMT(Double.parseDouble(df.format(cellValue.getNumberValue())));
}else if(cellValue.getCellType()==0){break;
}/***此处代码为网络摘录****/
//if (cellValue == null) {//continue;//}// //经过公式解析,最后只存在Boolean、Numeric和String三种数据类型,此外就是Error了// //其余数据类型,根据官方文档,完全可以忽略.html//switch (cellValue.getCellType()) {//case Cell.CELL_TYPE_BOOLEAN://sb.append(SEPARATOR + cellValue.getBooleanValue());//break;//case Cell.CELL_TYPE_NUMERIC:// //这里的日期类型会被转换为数字类型,需要判别后区分处理//if (DateUtil.isCellDateFormatted(cell)) {//sb.append(SEPARATOR + cell.getDateCellValue()+"---");//} else {//sb.append(SEPARATOR + cellValue.getNumberValue()+"+++");//}//break;//case Cell.CELL_TYPE_STRING://sb.append(SEPARATOR + cellValue.getStringValue());//break;//case Cell.CELL_TYPE_FORMULA://break;//case Cell.CELL_TYPE_BLANK://break;//case Cell.CELL_TYPE_ERROR://break;//default://break;//}
}
System.out.println();
list.add(sb.toString());
listPayment.add(payvoDataVo);
}
paymentDao.addPaymentDataVos(listPayment);
}catch(Exception e) {return false;//e.printStackTrace();
}return true;
}
更多推荐
java 数据库传输工具
发布评论