java 数据库传输工具

编程入门 行业动态 更新时间:2024-10-15 20:17:32

java <a href=https://www.elefans.com/category/jswz/34/1771350.html style=数据库传输工具"/>

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 数据库传输工具

本文发布于:2024-02-27 15:08:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1707046.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   工具   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!