当前位置 博文首页 > 俺叫啥好嘞的博客:java参考代码(ocr sheet)

    俺叫啥好嘞的博客:java参考代码(ocr sheet)

    作者:[db:作者] 时间:2021-09-14 16:21

    
    	public List readDByxsDataExcel(InputStream is,int num,int count,Map<String, String> map,String createdBy) throws 
    
    	IOException
    		{
    	
    			List list = new ArrayList();
    			List erroList = new ArrayList();
    			DecimalFormat df = new DecimalFormat("#");
    			// 创建对Excel工作簿文件的引用
    			HSSFWorkbook workbook;
    			workbook = new HSSFWorkbook(is);
    			int sheetNum = workbook.getNumberOfSheets();
    			// 循环sheet(列数目)
    	
    			for (int i = 0; i < sheetNum; i++)
    			{
    			
    				HSSFSheet childSheet = workbook.getSheetAt(i);
    
    				// 循环该 row
    				int recordNum = childSheet.getLastRowNum();
    				int endNun=0;
    				if (recordNum-num*count>=0) {
    					endNun=num*count;
    				}else {
    					endNun=recordNum;
    				}
    				for (int j = count*(num-1)+1; j <= endNun; j++)
    				{
    					String erro = "";
    					boolean flag = false;
    					//ApplyExamZsgl applyExamZsgl = new ApplyExamZsgl();
    					ApplyExam applyExam = new ApplyExam();
    
    					// 循环该子sheet行对应的单元格项
    					HSSFRow row = childSheet.getRow(j);
    					if (null == row)
    					{
    						continue;
    					}
    					int cellNum = row.getLastCellNum();
    					for (short k = 0; k < cellNum; k++)
    					{
    						
    						HSSFCell cell = row.getCell(k);
    						String value = null;
    						if (cell == null)
    							continue;
    
    						if (cell.getCellType()!=1) {
    							if (cell.getCellType()!=Cell.CELL_TYPE_NUMERIC) {
    								flag=true;
    								erro+="第"+(k+1)+"列,类型错误;";
    								break;
    							}else {
    								value=df.format(cell.getNumericCellValue())+"";
    							}
    						}else {							
    							value = cell.getStringCellValue();
    						}
    						if (k == 0)
    						{
    							applyExam.setIdentityCard(value.trim());
    							//applyExamZsgl.setUserName(value.trim());
    						}
    
    						if (k == 1)
    						{
    							applyExam.setKsZkz(value.trim());
    							//applyExamZsgl.setIdentityCard(value.trim());
    						}
    						
    						
    						if (k == 2)
    						{
    							applyExam.setAddress(value.trim());
    							//applyExamZsgl.setZsdj(value.trim());
    						}
    						/*if (k == 3)
    						{
    							applyExamZsgl.setXxTypeName(value.trim());
    						}*/
    
    					}
    			
    					ApplyExamCjErro applyExamCjErro = new ApplyExamCjErro();
    					
    					//applyExamCjErro.setIdentityCard(applyExamZsgl.getIdentityCard());
    					applyExamCjErro.setIdentityCard(applyExam.getIdentityCard());
    					//applyExamCjErro.setCurCode(applyExamZsgl.getZsbh());
    					//applyExamCjErro.setCurName(DateTimeUtil.dateToString(applyExamZsgl.getZsDate(),"yyyy-MM-dd"));
    					/*applyExamCjErro.setSubjectCode(applyExamZsgl.getZsdj());
    					applyExamCjErro.setUserName(applyExamZsgl.getUserName());
    					applyExamCjErro.setErrType(2);*/
    					applyExamCjErro.setSubjectCode(applyExam.getSubjectCode());
    					applyExamCjErro.setUserName(applyExam.getUserName());
    					applyExamCjErro.setErrType(100);
    				if (flag) {
    					applyExamCjErro.setErrValue(erro);
    					erroList.add(applyExamCjErro);
    				}else {
    					//String name= map.get(applyExamZsgl.getIdentityCard().trim().toUpperCase()+applyExamZsgl.getZsdj().trim()+applyExamZsgl.getXxTypeName());
    					String name= map.get(applyExam.getIdentityCard().trim()+applyExam.getKsZkz().trim());
    					if(StringHelper.isNotNull(name)){
    						String[] sp = name.split(",");
    						if(sp.length == 3){
    							applyExam.setId(Long.valueOf(sp[0]));
    							String createDate = sp[1];
    							String applyTime = sp[2];
    							SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    							String[] c = createDate.split("-");
    							if(c.length == 3){
    								String d = "2019-12-"+c[2];
    								try{
    									applyExam.setAddress(d);
    									applyExam.setCreatedDate(sim.parse(d));
    									applyExam.setApplyTime(sim.parse(d));
    								}catch(Exception e){
    									e.printStackTrace();
    									System.out.println("异常:");
    								}
    							}
    							list.add(applyExam);
    						}
    					}
    					
    					/*String temName[]=null;
    					if(StringHelper.isNotNull(name))
                        {
    					  temName=name.split(",");
                        }
    					if (name==null||name.equals("")) {
    						applyExamCjErro.setErrValue("身份证号码或专业代码输入错误!");
    						erroList.add(applyExamCjErro);
    					}else if (!temName[0].equals(applyExamZsgl.getUserName().trim())) {
    						erroList.add(applyExamCjErro);
    						applyExamCjErro.setErrValue("姓名输入错误!");
    					}else{	
    						
    						
    						
    						applyExamZsgl.setZsType(2);
    						applyExamZsgl.setStudentid(temName[1]);
    						
    						applyExamZsgl.setApplySchool(String.valueOf(temName[2]));
    					
    						if(StringHelper.isNotNull(temName[3])&&!temName[3].equals("null"))
    						{
    							
    						applyExamZsgl.setSchoolId(Long.valueOf(temName[3]));
    						}
    						applyExamZsgl.setEnabledFlag(Constants.ENABLED_FLAG_Y);
    						applyExamZsgl.setBkZkz(String.valueOf(temName[4]));
    						applyExamZsgl.setCreatedBy(createdBy);
    						applyExamZsgl.setCreatedDate(new Date());
    						
    						list.add(applyExamZsgl);
    					}*/
    				}
    				}
    			}
    			
    			ApplyExamCjErroManager mgr = (ApplyExamCjErroManager) ManagerBeanHelper.getBean("applyExamCjErroManager");
    			if(erroList!=null&&erroList.size()>0)
    			{
    			 mgr.saveApplyExamCjErros(erroList);
    			}
    			return list;
    		}
    		
    		
    
    
    
    INSERT INTO `hxy_thesis`.`ht_student_info`(`si_id`, `si_name`, `si_IDCard`, `si_phone`, `si_mailbox`, `si_photo_url`, `si_ID_front_url`, `si_ID_back_url`, `si_major_id`, `si_major_code`, `si_major_name`, `si_college_id`, `si_add_type`, `si_addtime`, `si_delete`, `si_operation_id`, `si_operation_name`, `si_number`, `si_write_thesis_audit`) VALUES (1436, '测试学生答辩', '420203199007031040 ', '15733185605', NULL, NULL, NULL, NULL, 13, '050408', '艺术教育(音乐)', 13, 3, 1596719337, 0, 1, '超级管理员', NULL, NULL);
    
    //自定义
            String host = "https://****.com";
            String path = "/ocrservice/et";
            String method = "POST";