關於java poi匯入匯出excel的包衝突問題
阿新 • • 發佈:2019-02-01
這個問題折騰了我半天,我的匯入和匯出分別用了連個poi包,這兩個包衝突,刪掉其中一個,則另一個功能就不能使用,很糾結,試了很多方法,但是我的import的工具的版本還不能換,版本必須一致,所以我決定,刪除一個版本,我的兩個版本分別位poi-3.8和poi2.2,因為poi-2.2中沒有Cell這個類,所以我刪除poi3.8我的action就會報錯,我索性刪除了poi3.8看看有沒有別的方法,把Cell刪除
HSSFRow row = sheet.getRow(i); // 獲取一行每一列的資料 HSSFCell userCodeCell = row.getCell(0); HSSFCell userNameCell = row.getCell(1); row.getCell(2).setCellType(Cell.CELL_TYPE_STRING); HSSFCell passWordCell = row.getCell(2); HSSFCell userDescriptionCell = row.getCell(3); HSSFCell userStateCell = row.getCell(4); HSSFCell superPopedomFlagCell = row.getCell(5); HSSFCell validStartDateCell = row.getCell(6); HSSFCell validEndDateCell = row.getCell(7); // HSSFCell pwdFlagDateCell=row.getCell(8); HSSFCell userEmailCell = row.getCell(8); String userCode = userCodeCell.getRichStringCellValue() .getString(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String validStartDate = new java.text.SimpleDateFormat( "yyyy-MM-dd").format(validStartDateCell .getDateCellValue()); String userName = userNameCell.getRichStringCellValue() .getString(); String passWord = passWordCell.getRichStringCellValue() .getString(); String userDescription = userDescriptionCell .getRichStringCellValue().getString(); String userState = userStateCell.getRichStringCellValue() .getString(); String superPopedomFlag = superPopedomFlagCell .getRichStringCellValue().getString(); String validEndDate = new java.text.SimpleDateFormat( "yyyy-MM-dd").format(validEndDateCell .getDateCellValue()); System.out.println(userCode + "--" + userName + "--" + passWord + "--" + userState + "--" + superPopedomFlag + "--" + validEndDate); String userEmail = userEmailCell.getRichStringCellValue() .getString();
這個是刪除之前的方法,修改之後====
HSSFRow row = sheet.getRow(i); // 獲取一行每一列的資料 HSSFCell planNameCell = row.getCell((short) 0); HSSFCell planPersonCell = row.getCell((short) 1); HSSFCell tierCodeCell = row.getCell((short) 2); HSSFCell carCodeCell = row.getCell((short) 3); HSSFCell planAddressCell = row.getCell((short) 4); HSSFCell planLevelCell = row.getCell((short) 5); HSSFCell planTimeCell = row.getCell((short) 6); // HSSFCell pwdFlagDateCell=row.getCell(8); HSSFCell planPictureCell = row.getCell((short) 7); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String planTime = new java.text.SimpleDateFormat( "yyyy-MM-dd").format(planTimeCell .getDateCellValue()); String planName = planNameCell .getStringCellValue(); String planPerson = planPersonCell .getStringCellValue(); String tierCode = tierCodeCell .getStringCellValue(); String carCode = carCodeCell .getStringCellValue(); String planAddress = planAddressCell .getStringCellValue(); String planLevel = planLevelCell .getStringCellValue(); String planPicture = planPictureCell .getStringCellValue(); File fi = new File(planPicture); String fileName= planPicture.substring(planPicture.lastIndexOf("\\")+1); if(fi.exists()){ fi.mkdirs(); }
把Cell去掉了,換了另一種方式取值,可能新舊版本不相容,新版本有新的類加入所以只能這樣,好糾結,特寫此文,以緬情懷