public ResponseData Lsryfjsj() throws IOException {
String str = "url链接地址" ;
//将下载链接转换为输入流
InputStream is = HttpUtil.createGet(str).execute().bodyStream();
System.out.println(is);
Workbook wb = new HSSFWorkbook(is);
List lsrykqjbxxList=readExcelValue(wb);
return new ResponseData(lsrykqjbxxList) ;
}
private List readExcelValue(Workbook wb) {
// 得到第一个shell
Sheet sheet = wb.getSheetAt(0);
// 得到Excel的行数
this.totalRows = sheet.getPhysicalNumberOfRows();
// 得到Excel的列数(前提是有行数)
if (totalRows > 1 && sheet.getRow(0) != null) {
this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
}
List userList = new ArrayList();
// 循环Excel行数
for (int r = 1; r < totalRows; r++) {
Row row = sheet.getRow(r);
if (row == null){
continue;
}
Lsrykqjbxx lsrykqjbxx= new Lsrykqjbxx();
// 循环Excel的列
for (int c = 0; c < this.totalCells; c++) {
Cell cell = row.getCell(c);
if (null != cell) {
if (c == 0) {
//如果是纯数字,比如你写的是25,cell.getNumericCellValue()获得是25.0,通过截取字符串去掉.0获得25
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
String bmmc = String.valueOf(cell.getNumericCellValue());
lsrykqjbxx.setBmmc(bmmc.substring(0, bmmc.length()-2>0?bmmc.length()-2:1));//部门名称
}else{
lsrykqjbxx.setBmmc(cell.getStringCellValue());//部门名称
}
} else if (c == 1) {
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
String gwlb = String.valueOf(cell.getNumericCellValue());
lsrykqjbxx.setGwlb(gwlb.substring(0, gwlb.length()-2>0?gwlb.length()-2:1));//岗位类别
}else{
lsrykqjbxx.setGwlb(cell.getStringCellValue());//性别
}
} else if (c == 2){
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
String lpgh= String.valueOf(cell.getNumericCellValue());
lsrykqjbxx.setLpgh(lpgh.substring(0, lpgh.length()-2>0?lpgh.length()-2:1));//临聘工号
}else{
lsrykqjbxx.setLpgh(cell.getStringCellValue());//工号
}
}else if (c == 3){
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
String lpxm= String.valueOf(cell.getNumericCellValue());
lsrykqjbxx.setLpxm(lpxm.substring(0, lpxm.length()-2>0?lpxm.length()-2:1));//临聘姓名
}else{
lsrykqjbxx.setLpxm(cell.getStringCellValue());//临聘姓名
}
}else if (c == 4){
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
String kqqk= String.valueOf(cell.getNumericCellValue());
lsrykqjbxx.setKqqk(kqqk.substring(0, kqqk.length()-2>0?kqqk.length()-2:1));//考勤情况
}else{
lsrykqjbxx.setKqqk(cell.getStringCellValue());//考勤情况
}
}else if (c == 5){
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
String xpggz= String.valueOf(cell.getNumericCellValue());
lsrykqjbxx.setXpggz(xpggz.substring(0, xpggz.length()-2>0?xpggz.length()-2:1));//校聘岗工资
}else{
lsrykqjbxx.setXpggz(cell.getStringCellValue());//考勤情况
}
}else if (c == 6){
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
String bmggz= String.valueOf(cell.getNumericCellValue());
lsrykqjbxx.setBmggz(bmggz.substring(0, bmggz.length()-2>0?bmggz.length()-2:1));//部门岗工资
}else{
lsrykqjbxx.setBmggz(cell.getStringCellValue());//考勤情况
}
}else if (c == 7){
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
String xlgz= String.valueOf(cell.getNumericCellValue());
lsrykqjbxx.setXlgz(xlgz.substring(0, xlgz.length()-2>0?xlgz.length()-2:1));//校龄工资
}else{
lsrykqjbxx.setXlgz(cell.getStringCellValue());//校龄工资
}
}else if (c == 8){
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
String qt= String.valueOf(cell.getNumericCellValue());
lsrykqjbxx.setQt(qt.substring(0, qt.length()-2>0?qt.length()-2:1));//其他
}else{
lsrykqjbxx.setQt(cell.getStringCellValue());//其他
}
}else if (c == 9){
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
String bfgz= String.valueOf(cell.getNumericCellValue());
lsrykqjbxx.setBfgz(bfgz.substring(0, bfgz.length()-2>0?bfgz.length()-2:1));//补发工资
}else{
lsrykqjbxx.setBfgz(cell.getStringCellValue());//补发工资
}
}else if (c == 10){
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
String yfgz= String.valueOf(cell.getNumericCellValue());
lsrykqjbxx.setYfgz(yfgz.substring(0, yfgz.length()-2>0?yfgz.length()-2:1));//应发工资
}else{
lsrykqjbxx.setYfgz(cell.getStringCellValue());//应发工资
}
}else if (c == 11){
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
String bz= String.valueOf(cell.getNumericCellValue());
lsrykqjbxx.setBz(bz.substring(0, bz.length()-2>0?bz.length()-2:1));//备注
}else{
lsrykqjbxx.setBz(cell.getStringCellValue());//备注
}
}
}
}
// 添加到list
userList.add(lsrykqjbxx);
}
return userList;
}