資源簡(jiǎn)介
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或錯(cuò)誤信息
?????*?@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頁(yè)
????????????XSSFSheet?sheet?=?workbook.getSheetAt(sheetindex);
????????????int?endcolumn=11;?????//“結(jié)束“所在列
????????????int?row=2;????????????//數(shù)據(jù)真正開(kāi)始行
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(“結(jié)束“)){???????????????
???????????? Student_1?vo?=?new?Student_1();
????????????????//檢查sheet頁(yè)中是否有信息缺失
????????????????for(int?column=0;column ???????????????? if(thisrow.getCell(column).getCellType()==XSSFCell.CELL_TYPE_BLANK){
?????????????????? ?resultmap.put(“Message“?sheet.getSheetName()+“第“+(row+1)+“行“+(column+1)+“列無(wú)數(shù)據(jù)“);
?????????????????? ?return?resultmap;
?????????????????? ?}
???????????????? if(column<6?||column>8){
???????????????? thisrow.getCell(column).setCellType(XSSFCell.CELL_TYPE_STRING);
???????????????? }
???????????????? }
????????????????//部門(mén)簡(jiǎn)稱(chēng)暫存為部門(mén)編號(hào)
????????????????//設(shè)置相應(yīng)的vo類(lèi)的屬性
????????????????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(“普通級(jí)“)){
???????????????? vo.setProjectLvlCd(3);
????????????????}else?if(levelname.equals(“大區(qū)級(jí)“)){
???????????????? vo.setProjectLvlCd(2);
????????????????}else?if(levelname.equals(“業(yè)務(wù)群“)){
???????????????? vo.setProjectLvlCd(1);
????????????????}else?if(levelname.equals(“FSG級(jí)“)){
???????????????? vo.setProjectLvlCd(0);
????????????????}else{
???????????????? resultmap.put(“Message“?“第“+sheetindex+?“個(gè)sheet頁(yè)第“+row+“行?項(xiàng)目級(jí)別信息有誤“);
??????????? ????return?resultmap;
????????????????}*/
????????????????
????????????????
//?????????????
評(píng)論
共有 條評(píng)論