資源簡介
http://blog.csdn.net/meng564764406/article/details/52444644
http://blog.csdn.net/meng564764406/article/details/52426634
源碼
代碼片段和文件信息
package?com.app.action;
import?java.io.File;
import?java.io.FileInputStream;
import?java.io.IOException;
import?java.math.BigDecimal;
import?java.text.ParseException;
import?java.text.SimpleDateFormat;
import?java.util.ArrayList;
import?java.util.Date;
import?java.util.HashMap;
import?java.util.List;
import?org.apache.poi.xssf.usermodel.XSSFWorkbook;
import?org.apache.poi.xssf.usermodel.XSSFCell;
import?org.apache.poi.xssf.usermodel.XSSFRow;
import?org.apache.poi.xssf.usermodel.XSSFSheet;
import?com.app.po.Student_1;
public?class?ReadXls?{
/**
?????*?讀取excel文件??大看板信息??返回HashMap中包含List或錯誤信息
?????*?@param?file
?????*?@return
?????*/
public?static?HashMapject>?getXlsxxBigProjList(File?file)?throws?Exception{?
???? HashMapject>??resultmap=new?HashMapject>();
???? List?list?=?new?ArrayList();
????????try?{???????
????????????XSSFWorkbook?workbook=new?XSSFWorkbook(file.getAbsolutePath());
????????????int?sheetindex=0;?????//大看板信息所在sheet頁
????????????XSSFSheet?sheet?=?workbook.getSheetAt(sheetindex);
????????????int?endcolumn=11;?????//“結束“所在列
????????????int?row=2;????????????//數據真正開始行
XSSFRow?thisrow=sheet.getRow(row);
thisrow.getCell(endcolumn).setCellType(XSSFCell.CELL_TYPE_STRING);
while(thisrow.getCell(0).getCellType()!=XSSFCell.CELL_TYPE_BLANK?&&?!thisrow.getCell(endcolumn).getStringCellValue().trim().equals(“結束“)){???????????????
???????????? Student_1?vo?=?new?Student_1();
????????????????//檢查sheet頁中是否有信息缺失
????????????????for(int?column=0;column ???????????????? if(thisrow.getCell(column).getCellType()==XSSFCell.CELL_TYPE_BLANK){
?????????????????? ?resultmap.put(“Message“?sheet.getSheetName()+“第“+(row+1)+“行“+(column+1)+“列無數據“);
?????????????????? ?return?resultmap;
?????????????????? ?}
???????????????? if(column<6?||column>8){
???????????????? thisrow.getCell(column).setCellType(XSSFCell.CELL_TYPE_STRING);
???????????????? }
???????????????? }
????????????????//部門簡稱暫存為部門編號
????????????????//設置相應的vo類的屬性
????????????????vo.setNo(thisrow.getCell(0).getStringCellValue());???????????????
????????????????vo.setName(thisrow.getCell(1).getStringCellValue());?
????????????????vo.setAge(thisrow.getCell(2).getStringCellValue());
????????????????vo.setScore(thisrow.getCell(3).getStringCellValue());
????????????????/*String?levelname=thisrow.getCell(3).getStringCellValue().trim();
????????????????if(levelname.equals(“普通級“)){
???????????????? vo.setProjectLvlCd(3);
????????????????}else?if(levelname.equals(“大區級“)){
???????????????? vo.setProjectLvlCd(2);
????????????????}else?if(levelname.equals(“業務群“)){
???????????????? vo.setProjectLvlCd(1);
????????????????}else?if(levelname.equals(“FSG級“)){
???????????????? vo.setProjectLvlCd(0);
????????????????}else{
???????????????? resultmap.put(“Message“?“第“+sheetindex+?“個sheet頁第“+row+“行?項目級別信息有誤“);
??????????? ????return?resultmap;
????????????????}*/
????????????????
????????????????
//?????????????
評論
共有 條評論