package com.qmth.qrzk.repositry.utils.excel;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONObject;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.qmth.qrzk.repository.task.PaperTask;
import com.qmth.qrzk.repository.user.model.AuditQuesTask;
import com.qmth.qrzk.repository.user.model.ImportBean;
import com.qmth.qrzk.repository.utils.General;


/**
 * 解析excel并生成相应任务对象集合
 * @author 钟辉
 *
 */
public class ExcelOperate {

	/**
	 * 解析试卷启用的Excel
	 * 
	 * @return
	 * @throws IOException
	 */
	public List<ImportBean> readStartedPaperExcel(InputStream stream,String fileName) {
		String postfix = Util.getPostfix(fileName);
		if (!Common.EMPTY.equals(postfix)) {
			if (Common.OFFICE_EXCEL_2003_POSTFIX.equals(postfix)) {
				try {
					return readStartedPaperXls(stream);
				} catch (IOException e) {
					e.printStackTrace();
				}
			} else if (Common.OFFICE_EXCEL_2010_POSTFIX.equals(postfix)) {
				try {
					return readStartedPaperXlsx(stream);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		} 
		return null;
	}

	/**
	 * 解析入闱命题任务的Excel
	 * 
	 * @return
	 * @throws IOException
	 */
	public List<PaperTask> readPaperTaskExcel(InputStream stream,String fileName,JSONObject object) {
		String postfix = Util.getPostfix(fileName);
		if (!Common.EMPTY.equals(postfix)) {
			if (Common.OFFICE_EXCEL_2003_POSTFIX.equals(postfix)) {
				try {
					return readPaperTaskXls(stream,object);
				} catch (IOException e) {
					e.printStackTrace();
				}
			} else if (Common.OFFICE_EXCEL_2010_POSTFIX.equals(postfix)) {
				try {
					return readPaperTaskXlsx(stream,object);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		} 
		return null;
	}
	
	/**
	 * 解析试卷复审任务的Excel
	 * 
	 * @return
	 * @throws IOException
	 */
	public List<PaperTask> readReviewTaskExcel(InputStream stream,String fileName,JSONObject object) {
		String postfix = Util.getPostfix(fileName);
		if (!Common.EMPTY.equals(postfix)) {
			if (Common.OFFICE_EXCEL_2003_POSTFIX.equals(postfix)) {
				try {
					return readReviewTaskXls(stream,object);
				} catch (IOException e) {
					e.printStackTrace();
				}
			} else if (Common.OFFICE_EXCEL_2010_POSTFIX.equals(postfix)) {
				try {
					return readReviewTaskXlsx(stream,object);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		} 
		return null;
	}

	/**
	 * 解析审题任务的Excel
	 * 
	 * @return
	 * @throws IOException
	 */
	public List<AuditQuesTask> readAuditQuesTaskExcel(InputStream stream,String fileName,JSONObject object) {
		String postfix = Util.getPostfix(fileName);
		if (!Common.EMPTY.equals(postfix)) {
			if (Common.OFFICE_EXCEL_2003_POSTFIX.equals(postfix)) {
				try {
					return readAuditQuesTaskXls(stream,object);
				} catch (IOException e) {
					e.printStackTrace();
				}
			} else if (Common.OFFICE_EXCEL_2010_POSTFIX.equals(postfix)) {
				try {
					return readAuditQuesTaskXlsx(stream,object);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		} 
		return null;
	}
	
	/**
	 * 读取课程以及关联的教材excel
	 * @param stream
	 * @param fileName
	 * @return
	 */
	public List<ImportBean> readCourseBookExcel(InputStream stream,String fileName) {
		String postfix = Util.getPostfix(fileName);
		if (!Common.EMPTY.equals(postfix)) {
			if (Common.OFFICE_EXCEL_2003_POSTFIX.equals(postfix)) {
				try {
					return readCourseBookXls(stream);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else if (Common.OFFICE_EXCEL_2010_POSTFIX.equals(postfix)) {
				try {
					return readCourseBookXlsx(stream);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		} 
		return null;
	}
	
	/**
	 * 读取题型excel
	 * @param stream
	 * @param fileName
	 * @return
	 */
	public List<ImportBean> readQuestionTypeExcel(InputStream stream,String fileName) {
		String postfix = Util.getPostfix(fileName);
		if (!Common.EMPTY.equals(postfix)) {
			if (Common.OFFICE_EXCEL_2003_POSTFIX.equals(postfix)) {
				try {
					return readQuestionTypeXls(stream);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else if (Common.OFFICE_EXCEL_2010_POSTFIX.equals(postfix)) {
				try {
					return readQuestionTypeXlsx(stream);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		} 
		return null;
	}
	
	/**
	 * 读取命题教师excel
	 * @param stream
	 * @param fileName
	 * @return
	 */
	public List<ImportBean> readTeacherExcel(InputStream stream,String fileName) {
		String postfix = Util.getPostfix(fileName);
		if (!Common.EMPTY.equals(postfix)) {
			if (Common.OFFICE_EXCEL_2003_POSTFIX.equals(postfix)) {
				try {
					return readTeacherXls(stream);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else if (Common.OFFICE_EXCEL_2010_POSTFIX.equals(postfix)) {
				try {
					return readTeacherXlsx(stream);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		} 
		return null;
	}
	
	/**
	 * 读取学科秘书excel
	 * @param stream
	 * @param fileName
	 * @return
	 */
	public List<ImportBean> readSecretaryExcel(InputStream stream,String fileName) {
		
		String postfix = Util.getPostfix(fileName);
		if (!Common.EMPTY.equals(postfix)) {
			if (Common.OFFICE_EXCEL_2003_POSTFIX.equals(postfix)) {
				try {
					return readSecretaryXls(stream);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else if (Common.OFFICE_EXCEL_2010_POSTFIX.equals(postfix)) {
				try {
					return readSecretaryXlsx(stream);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		} 
		return null;
	}
	
	/**
	 * 读取录入员excel
	 * @param stream
	 * @param fileName
	 * @return
	 */
	public List<ImportBean> readInputExcel(InputStream stream,String fileName) {
		
		String postfix = Util.getPostfix(fileName);
		if (!Common.EMPTY.equals(postfix)) {
			if (Common.OFFICE_EXCEL_2003_POSTFIX.equals(postfix)) {
				try {
					return readInputXls(stream);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else if (Common.OFFICE_EXCEL_2010_POSTFIX.equals(postfix)) {
				try {
					return readInputXlsx(stream);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		} 
		return null;
	}
	
	/**
	 * 读取命题教师课程关联的excel
	 * @param stream
	 * @param fileName
	 * @return
	 */
	public List<ImportBean> readTeacherCourseExcel(InputStream stream,String fileName) {
		String postfix = Util.getPostfix(fileName);
		if (!Common.EMPTY.equals(postfix)) {
			if (Common.OFFICE_EXCEL_2003_POSTFIX.equals(postfix)) {
				try {
					return readTeacherCourseXls(stream);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else if (Common.OFFICE_EXCEL_2010_POSTFIX.equals(postfix)) {
				try {
					return readTeacherCourseXlsx(stream);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		} 
		return null;
	}

	private List<PaperTask> readPaperTaskXlsx(InputStream stream,JSONObject object) throws IOException {
		// System.out.println(Common.PROCESSING + path);
		XSSFWorkbook xssfWorkbook = new XSSFWorkbook(stream);
		PaperTask paperTask = null;
		List<PaperTask> list = new ArrayList<PaperTask>();
		// Read the Sheet
		for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
			XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
			if (xssfSheet == null) {
				continue;
			}
			XSSFRow titleRow = xssfSheet.getRow(0);
			if(!"课程代码*".equals(getValue(titleRow.getCell(0)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 0) + "的标题名为：课程代码*");
				return null;
			}
			if(!"课程名称*".equals(getValue(titleRow.getCell(1)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 1) + "的标题名为：课程名称*");
				return null;
			}
			if(!"命题教师1*".equals(getValue(titleRow.getCell(2)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 2) + "的标题名为：命题教师1*");
				return null;
			}
			if(!"命题教师2*".equals(getValue(titleRow.getCell(3)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 3) + "的标题名为：命题教师2*");
				return null;
			}
			if(!"学科秘书1*".equals(getValue(titleRow.getCell(4)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 4) + "的标题名为：学科秘书1*");
				return null;
			}
			if(!"学科秘书2*".equals(getValue(titleRow.getCell(5)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 5) + "的标题名为：学科秘书2*");
				return null;
			}
			if(!"排版员*".equals(getValue(titleRow.getCell(6)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 6) + "的标题名为：排版员*");
				return null;
			}
			// Read the Row
			for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
				XSSFRow xssfRow = xssfSheet.getRow(rowNum);
				if (xssfRow != null) {
					XSSFCell courseId = xssfRow.getCell(0);
					XSSFCell courseName = xssfRow.getCell(1);
					XSSFCell propositionTeacher = xssfRow.getCell(2);
					XSSFCell auditTeacher = xssfRow.getCell(3);
					XSSFCell primarySecretary = xssfRow.getCell(4);
					XSSFCell assistantSecretary = xssfRow.getCell(5);
					XSSFCell typeSetter = xssfRow.getCell(6);
					if(courseId==null||courseName==null||propositionTeacher==null||auditTeacher==null||primarySecretary==null||assistantSecretary==null||typeSetter==null){
						object.put("result", "fail");
						object.put("lineNum",rowNum);
						object.put("msg", "此行信息不完整");
						return null;
					}
					paperTask=new PaperTask(getValue(courseId),getValue(courseName),getValue(propositionTeacher),getValue(auditTeacher),getValue(typeSetter),getValue(primarySecretary),getValue(assistantSecretary));
					list.add(paperTask);
				}
			}
		}
		return list;
	}
	
	/**
	 * 解析试卷复审
	 * @param stream
	 * @param object
	 * @return
	 * @throws IOException
	 */
	private List<PaperTask> readReviewTaskXlsx(InputStream stream,JSONObject object) throws IOException {
		// System.out.println(Common.PROCESSING + path);
		XSSFWorkbook xssfWorkbook = new XSSFWorkbook(stream);
		PaperTask paperTask = null;
		List<PaperTask> list = new ArrayList<PaperTask>();
		// Read the Sheet
//		for (int numSheet = 0; numSheet < 1; numSheet++) {
			XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
			if (xssfSheet == null) {
				return null;
			}
			XSSFRow titleRow = xssfSheet.getRow(0);
			if(!"试卷名称*".equals(getValue(titleRow.getCell(0)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 0) + "的标题名为：试卷名称*");
				return null;
			}
			if(!"命题教师*".equals(getValue(titleRow.getCell(1)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 1) + "的标题名为：命题教师*");
				return null;
			}
			if(!"学科秘书*".equals(getValue(titleRow.getCell(2)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 2) + "的标题名为：学科秘书*");
				return null;
			}
			if(!"排版员*".equals(getValue(titleRow.getCell(3)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 3) + "的标题名为：排版员*");
				return null;
			}
			// Read the Row
			for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
				XSSFRow xssfRow = xssfSheet.getRow(rowNum);
				if (xssfRow != null) {
					XSSFCell taskNo = xssfRow.getCell(0);
					XSSFCell auditTeacher = xssfRow.getCell(1);
					XSSFCell primarySecretary = xssfRow.getCell(2);
					XSSFCell typeSetter = xssfRow.getCell(3);
					if(taskNo == null|| auditTeacher == null|| primarySecretary == null || typeSetter == null){
						object.put("result", "fail");
						object.put("lineNum",rowNum);
						object.put("msg", "此行信息不完整");
						return null;
					}
					if(getValue(taskNo).length() != 14){
						object.put("result", "fail");
						object.put("lineNum",rowNum);
						object.put("msg", getValue(taskNo) + "命名不符合规范");
						return null;
					}
					paperTask=new PaperTask(getValue(taskNo),getValue(auditTeacher),getValue(primarySecretary),getValue(typeSetter));
					list.add(paperTask);
				}
			}
//		}
		return list;
	}


	private List<AuditQuesTask> readAuditQuesTaskXlsx(InputStream stream,JSONObject object) throws IOException {
		XSSFWorkbook xssfWorkbook = new XSSFWorkbook(stream);
		List<AuditQuesTask> list = new ArrayList<AuditQuesTask>();
		// Read the Sheet
		for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
			XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
			if (xssfSheet == null) {
				continue;
			}
			XSSFRow titleRow = xssfSheet.getRow(0);
			if(!"课程代码*".equals(getValue(titleRow.getCell(0)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 0) + "的标题名为：课程代码*");
				return null;
			}
			if(!"课程名称*".equals(getValue(titleRow.getCell(1)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 1) + "的标题名为：课程名称*");
				return null;
			}
			if(!"审题教师列表*".equals(getValue(titleRow.getCell(2)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 2) + "的标题名为：审题教师列表*");
				return null;
			}
			// Read the Row
			for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
				XSSFRow xssfRow = xssfSheet.getRow(rowNum);
				if (xssfRow != null) {
					XSSFCell courseId = xssfRow.getCell(0);
					XSSFCell courseName = xssfRow.getCell(1);
					XSSFCell auditors = xssfRow.getCell(2);
					if(courseId==null||courseName==null||auditors==null){
						object.put("result", "fail");
						object.put("lineNum",rowNum);
						object.put("msg", "此行信息不完整");
						return null;
					}
					AuditQuesTask task = new AuditQuesTask(getValue(courseId),getValue(courseName),getValue(auditors));
					list.add(task);
				}
			}
		}
		return list;
	}
	
	/**
	 * 读取2003版本excel
	 * @param stream
	 * @return
	 * @throws IOException
	 */
	private List<ImportBean> readCourseBookXls(InputStream stream) throws IOException {
		HSSFWorkbook hssfWorkbook = new HSSFWorkbook(stream);
		ImportBean importCourseBean = null;
		List<ImportBean> list = new ArrayList<ImportBean>();
		boolean flag=true;
		// Read the Sheet
		for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
			HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
			if (hssfSheet == null) {
				continue;
			}
			// Read the Row
			if(flag){
				for (int rowNum = 0; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
					HSSFRow hssfRow = hssfSheet.getRow(rowNum);
					if (hssfRow != null) {
						HSSFCell courseCode = hssfRow.getCell(0);
						HSSFCell courseName = hssfRow.getCell(1);
						HSSFCell courseISBN = hssfRow.getCell(2);
						HSSFCell bookName = hssfRow.getCell(3);
						HSSFCell author = hssfRow.getCell(4);
						HSSFCell press = hssfRow.getCell(5);
						HSSFCell edition = hssfRow.getCell(6);
						HSSFCell bookStartTime = hssfRow.getCell(7);
						HSSFCell specialtyType = hssfRow.getCell(8);
						if(courseCode==null||courseName==null||bookName==null||author==null||press==null||specialtyType==null){
							break;
						}
						
						if(rowNum==0){
							//验证导入的格式是否正确
							if(getValue(courseCode).equals("课程代码")&&getValue(courseName).equals("课程名称")&&getValue(courseISBN).equals("教材ISBN")
									&&getValue(bookName).equals("教材名称")&&getValue(author).equals("编者")&&getValue(press).equals("出版社")
									&&getValue(edition).equals("版次")&&getValue(bookStartTime).equals("教材大纲启用时间")&&getValue(specialtyType).equals("专业类别")){
								flag=true;
								continue;
							}else{
								flag=false;
								break;
							}
						}
						importCourseBean=new ImportBean(getValue(courseCode),getValue(courseName));
						importCourseBean.setBookName(getValue(bookName));
						importCourseBean.setAuthor(getValue(author));
						importCourseBean.setPress(getValue(press));
						importCourseBean.setEdition(getValue(edition));
						importCourseBean.setBookStartTime(getValue(bookStartTime));
						importCourseBean.setSpecialtyType(getValue(specialtyType));
						importCourseBean.setCourseISBN(getValue(courseISBN));
						list.add(importCourseBean);
					}
				}
			}
		}
		return list;
	}
	
	
	private List<ImportBean> readCourseBookXlsx(InputStream stream) throws IOException {
		// System.out.println(Common.PROCESSING + path);
		XSSFWorkbook xssfWorkbook = new XSSFWorkbook(stream);
		ImportBean importCourseBean = null;
		List<ImportBean> list = new ArrayList<ImportBean>();
		boolean flag=true;
		// Read the Sheet
		for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
			XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
			if (xssfSheet == null) {
				continue;
			}
			if(flag){
				// Read the Row
				for (int rowNum = 0; rowNum <=xssfSheet.getLastRowNum(); rowNum++) {
					XSSFRow xssfRow = xssfSheet.getRow(rowNum);
					if (xssfRow != null) {
						XSSFCell courseCode = xssfRow.getCell(0);
						XSSFCell courseName = xssfRow.getCell(1);
						XSSFCell courseISBN = xssfRow.getCell(2);
						XSSFCell bookName = xssfRow.getCell(3);
						XSSFCell author = xssfRow.getCell(4);
						XSSFCell press = xssfRow.getCell(5);
						XSSFCell edition = xssfRow.getCell(6);
						XSSFCell bookStartTime = xssfRow.getCell(7);
						XSSFCell specialtyType = xssfRow.getCell(8);
						if(courseCode==null||courseName==null||bookName==null||author==null||press==null||specialtyType==null){
							break;
						}
						
						if(rowNum==0){
							//验证导入的格式是否正确
							if(getValue(courseCode).equals("课程代码")&&getValue(courseName).equals("课程名称")&&getValue(courseISBN).equals("教材ISBN")
									&&getValue(bookName).equals("教材名称")&&getValue(author).equals("编者")&&getValue(press).equals("出版社")
									&&getValue(edition).equals("版次")&&getValue(bookStartTime).equals("教材大纲启用时间")&&getValue(specialtyType).equals("专业类别")){
								flag=true;
								continue;
							}else{
								flag=false;
								break;
							}
						}
						importCourseBean=new ImportBean(getValue(courseCode),getValue(courseName));
						importCourseBean.setBookName(getValue(bookName));
						importCourseBean.setAuthor(getValue(author));
						importCourseBean.setPress(getValue(press));
						importCourseBean.setEdition(getValue(edition));
						importCourseBean.setBookStartTime(getValue(bookStartTime));
						importCourseBean.setSpecialtyType(getValue(specialtyType));
						importCourseBean.setCourseISBN(getValue(courseISBN));
						list.add(importCourseBean);
					}	
				}
			}
		}
		return list;
	}
	
	
	private List<ImportBean> readQuestionTypeXlsx(InputStream stream) throws IOException {
		// System.out.println(Common.PROCESSING + path);
		XSSFWorkbook xssfWorkbook = new XSSFWorkbook(stream);
		ImportBean importCourseBean = null;
		List<ImportBean> list = new ArrayList<ImportBean>();
		
		boolean flag=true;
		// Read the Sheet
		for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
			XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
			if (xssfSheet == null) {
				continue;
			}
			if(flag){
				// Read the Row
				for (int rowNum = 0; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
					XSSFRow xssfRow = xssfSheet.getRow(rowNum);
					if (xssfRow != null) {
						XSSFCell courseCode = xssfRow.getCell(0);
						XSSFCell questionCode = xssfRow.getCell(1);
						XSSFCell questionName = xssfRow.getCell(2);
						if(courseCode==null||questionName==null){
							break;
						}
						if(rowNum==0){
							//验证导入的格式是否正确
							if(getValue(courseCode).equals("课程代码")&&getValue(questionCode).equals("题型代码")&&getValue(questionName).equals("题型名称")){
								flag=true;
								continue;
							}else{
								flag=false;
								break;
							}
						}
						importCourseBean=new ImportBean();
						importCourseBean.setCourseCode(getValue(courseCode));
						importCourseBean.setQuestionCode(getValue(questionCode));
						importCourseBean.setQuestionName(getValue(questionName));
						list.add(importCourseBean);
					}	
				}
			}
		}
		return list;
	}
	private List<ImportBean> readQuestionTypeXls(InputStream stream) throws IOException {
		HSSFWorkbook hssfWorkbook = new HSSFWorkbook(stream);
		ImportBean importCourseBean = null;
		List<ImportBean> list = new ArrayList<ImportBean>();
		boolean flag=true;
		// Read the Sheet
		for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
			HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
			if (hssfSheet == null) {
				continue;
			}
			// Read the Row
			if(flag){
				for (int rowNum = 0; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
					HSSFRow hssfRow = hssfSheet.getRow(rowNum);
					if (hssfRow != null) {
						HSSFCell courseCode = hssfRow.getCell(0);
						HSSFCell questionCode = hssfRow.getCell(1);
						HSSFCell questionName = hssfRow.getCell(2);
						if(courseCode==null||questionName==null){
							break;
						}
						if(rowNum==0){
							//验证导入的格式是否正确
							if(getValue(courseCode).equals("课程代码")&&getValue(questionCode).equals("题型代码")&&getValue(questionName).equals("题型名称")){
								flag=true;
								continue;
							}else{
								flag=false;
								break;
							}
						}
						importCourseBean=new ImportBean();
						importCourseBean.setCourseCode(getValue(courseCode));
						importCourseBean.setQuestionCode(getValue(questionCode));
						importCourseBean.setQuestionName(getValue(questionName));
						list.add(importCourseBean);
					}
				}
			}
		}
		return list;
	}
	/**
	 * 读取2003版本excel
	 * @param stream
	 * @return
	 * @throws IOException
	 */
	private List<ImportBean> readTeacherXls(InputStream stream) throws IOException {
		HSSFWorkbook hssfWorkbook = new HSSFWorkbook(stream);
		ImportBean importCourseBean = null;
		List<ImportBean> list = new ArrayList<ImportBean>();
		boolean flag=true;
		// Read the Sheet
		for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
			HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
			if (hssfSheet == null) {
				continue;
			}
			// Read the Row
			if(flag){
				for (int rowNum = 0; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
					HSSFRow hssfRow = hssfSheet.getRow(rowNum);
					if (hssfRow != null) {
						HSSFCell name = hssfRow.getCell(0);
						HSSFCell gender = hssfRow.getCell(1);
						HSSFCell certino = hssfRow.getCell(2);
						HSSFCell position = hssfRow.getCell(3);
						HSSFCell school = hssfRow.getCell(4);
						HSSFCell department = hssfRow.getCell(5);
						HSSFCell officePhone = hssfRow.getCell(6);
						HSSFCell phone = hssfRow.getCell(7);
						HSSFCell email = hssfRow.getCell(8);
						if(name==null){
							break;
						}
						if(rowNum==0){
							//验证导入的格式是否正确
							if(getValue(name).equals("姓名")&&getValue(gender).equals("性别")&&getValue(certino).equals("身份证号")&&getValue(position).equals("职称")
									&&getValue(school).equals("单位")&&getValue(department).equals("院系")&&getValue(officePhone).equals("办公电话")&&getValue(phone).equals("手机")&&getValue(email).equals("Email")){
								flag=true;
								continue;
							}else{
								flag=false;
								break;
							}
						}
						importCourseBean=new ImportBean();
						importCourseBean.setName(getValue(name));
						if(gender!=null){
							importCourseBean.setGender(getValue(gender));
						}
						if(certino!=null){
							importCourseBean.setCertino(getValue(certino));
						}
						if(position!=null){
							importCourseBean.setPosition(getValue(position));
						}
						if(school!=null){
							importCourseBean.setSchool(getValue(school));
						}
						if(department!=null){
							importCourseBean.setDepartment(getValue(department));
						}
						if(officePhone!=null){
							importCourseBean.setOfficePhone(getValue(officePhone));
						}
						if(phone!=null){
							importCourseBean.setPhone(getValue(phone));
						}
						if(email!=null){
							importCourseBean.setEmail(getValue(email));
						}
						list.add(importCourseBean);
					}
				}
			}
		}
		return list;
	}
	
	/**
	 * 读取2007版本excel
	 * @param stream
	 * @return
	 * @throws IOException
	 */
	private List<ImportBean> readTeacherXlsx(InputStream stream) throws IOException {
		XSSFWorkbook xssfWorkbook = new XSSFWorkbook(stream);
		ImportBean importCourseBean = null;
		List<ImportBean> list = new ArrayList<ImportBean>();
		
		boolean flag=true;
		// Read the Sheet
		for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
			XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
			if (xssfSheet == null) {
				continue;
			}
			if(flag){
				// Read the Row
				for (int rowNum = 0; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
					XSSFRow xssfRow = xssfSheet.getRow(rowNum);
					if (xssfRow != null) {
						XSSFCell name = xssfRow.getCell(0);
						XSSFCell gender = xssfRow.getCell(1);
						XSSFCell certino = xssfRow.getCell(2);
						XSSFCell position = xssfRow.getCell(3);
						XSSFCell school = xssfRow.getCell(4);
						XSSFCell department = xssfRow.getCell(5);
						XSSFCell officePhone = xssfRow.getCell(6);
						XSSFCell phone = xssfRow.getCell(7);
						XSSFCell email = xssfRow.getCell(8);
						if(name==null){
							break;
						}
						if(rowNum==0){
							//验证导入的格式是否正确
							if(getValue(name).equals("姓名")&&getValue(gender).equals("性别")&&getValue(certino).equals("身份证号")&&getValue(position).equals("职称")
									&&getValue(school).equals("单位")&&getValue(department).equals("院系")&&getValue(officePhone).equals("办公电话")&&getValue(phone).equals("手机")&&getValue(email).equals("Email")){
								flag=true;
								continue;
							}else{
								flag=false;
								break;
							}
						}
						importCourseBean=new ImportBean();
						importCourseBean.setName(getValue(name));
						if(gender!=null){
							importCourseBean.setGender(getValue(gender));
						}
						if(certino!=null){
							importCourseBean.setCertino(getValue(certino));
						}
						if(position != null){
							importCourseBean.setPosition(getValue(position));
						}
						if(school!=null){
							importCourseBean.setSchool(getValue(school));
						}
						if(department!=null){
							importCourseBean.setDepartment(getValue(department));
						}
						if(officePhone!=null){
							importCourseBean.setOfficePhone(getValue(officePhone));
						}
						if(phone!=null){
							importCourseBean.setPhone(getValue(phone));
						}
						if(email!=null){
							importCourseBean.setEmail(getValue(email));
						}
						list.add(importCourseBean);
					}	
				}
			}
		}
		return list;
	}
	
	
	private List<ImportBean> readSecretaryXls(InputStream stream) throws IOException {
		HSSFWorkbook hssfWorkbook = new HSSFWorkbook(stream);
		ImportBean importCourseBean = null;
		List<ImportBean> list = new ArrayList<ImportBean>();
		boolean flag=true;
		// Read the Sheet
		for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
			HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
			if (hssfSheet == null) {
				continue;
			}
			// Read the Row
			if(flag){
				for (int rowNum = 0; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
					HSSFRow hssfRow = hssfSheet.getRow(rowNum);
					if (hssfRow != null) {
						HSSFCell name = hssfRow.getCell(0);
						HSSFCell gender = hssfRow.getCell(1);
						HSSFCell certino = hssfRow.getCell(2);
						HSSFCell major = hssfRow.getCell(3);
						HSSFCell officePhone = hssfRow.getCell(4);
						HSSFCell phone = hssfRow.getCell(5);
						if(name==null){
							break;
						}
						if(rowNum==0){
							//验证导入的格式是否正确
							if(getValue(name).equals("姓名")&&getValue(gender).equals("性别")&&getValue(certino).equals("身份证号 ")&&getValue(major).equals("专业")&&getValue(officePhone).equals("办公电话")&&getValue(phone).equals("手机")){
								flag=true;
								continue;
							}else{
								flag=false;
								break;
							}
						}
						importCourseBean=new ImportBean();
						importCourseBean.setName(getValue(name));
						if(gender!=null){
							importCourseBean.setGender(getValue(gender));
						}
						if(certino!=null){
							importCourseBean.setCertino(getValue(certino));
						}
						if(major!=null){
							importCourseBean.setMajor(getValue(major));
						}
						if(officePhone!=null){
							importCourseBean.setOfficePhone(getValue(officePhone));
						}
						if(phone!=null){
							importCourseBean.setPhone(getValue(phone));
						}
						list.add(importCourseBean);
					}
				}
			}
		}
		return list;
	}
	
	
	private List<ImportBean> readSecretaryXlsx(InputStream stream) throws IOException {
		// System.out.println(Common.PROCESSING + path);readSecretaryXls
		XSSFWorkbook xssfWorkbook = new XSSFWorkbook(stream);
		ImportBean importCourseBean = null;
		List<ImportBean> list = new ArrayList<ImportBean>();
		
		boolean flag=true;
		// Read the Sheet
		for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
			XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
			if (xssfSheet == null) {
				continue;
			}
			if(flag){
				// Read the Row
				for (int rowNum = 0; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
					XSSFRow xssfRow = xssfSheet.getRow(rowNum);
					if (xssfRow != null) {
						XSSFCell name = xssfRow.getCell(0);
						XSSFCell gender = xssfRow.getCell(1);
						XSSFCell certino = xssfRow.getCell(2);
						XSSFCell major = xssfRow.getCell(3);
						XSSFCell officePhone = xssfRow.getCell(4);
						XSSFCell phone = xssfRow.getCell(5);
						if(name==null){
							break;
						}
						if(rowNum==0){
							//验证导入的格式是否正确
							if(getValue(name).equals("姓名")&&getValue(gender).equals("性别")&&getValue(certino).equals("身份证号")&&getValue(major).equals("专业")&&getValue(officePhone).equals("办公电话")&&getValue(phone).equals("手机")){
								flag=true;
								continue;
							}else{
								flag=false;
								break;
							}
						}
						importCourseBean=new ImportBean();
						importCourseBean.setName(getValue(name));
						if(gender!=null){
							importCourseBean.setGender(getValue(gender));
						}
						if(certino!=null){
							importCourseBean.setCertino(getValue(certino));
						}
						if(major!=null){
							importCourseBean.setMajor(getValue(major));
						}
						if(officePhone!=null){
							importCourseBean.setOfficePhone(getValue(officePhone));
						}
						if(phone!=null){
							importCourseBean.setPhone(getValue(phone));
						}
						list.add(importCourseBean);
					}	
				}
			}
		}
		return list;
	}
	
	private List<ImportBean> readInputXls(InputStream stream) throws IOException {
		HSSFWorkbook hssfWorkbook = new HSSFWorkbook(stream);
		ImportBean importCourseBean = null;
		List<ImportBean> list = new ArrayList<ImportBean>();
		boolean flag=true;
		// Read the Sheet
		for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
			HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
			if (hssfSheet == null) {
				continue;
			}
			// Read the Row
			if(flag){
				for (int rowNum = 0; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
					HSSFRow hssfRow = hssfSheet.getRow(rowNum);
					if (hssfRow != null) {
						HSSFCell name = hssfRow.getCell(0);
						HSSFCell gender = hssfRow.getCell(1);
						HSSFCell certino = hssfRow.getCell(2);
						HSSFCell officePhone = hssfRow.getCell(3);
						HSSFCell phone = hssfRow.getCell(4);
						if(name==null){
							break;
						}
						if(rowNum==0){
							//验证导入的格式是否正确
							if(getValue(name).equals("姓名")&&getValue(gender).equals("性别")&&getValue(certino).equals("身份证号 ")&&getValue(officePhone).equals("办公电话")&&getValue(phone).equals("手机")){
								flag=true;
								continue;
							}else{
								flag=false;
								break;
							}
						}
						importCourseBean=new ImportBean();
						importCourseBean.setName(getValue(name));
						if(gender!=null){
							importCourseBean.setGender(getValue(gender));
						}
						if(certino!=null){
							importCourseBean.setCertino(getValue(certino));
						}
						if(officePhone!=null){
							importCourseBean.setOfficePhone(getValue(officePhone));
						}
						if(phone!=null){
							importCourseBean.setPhone(getValue(phone));
						}
						list.add(importCourseBean);
					}
				}
			}
		}
		return list;
	}
	
	
	private List<ImportBean> readInputXlsx(InputStream stream) throws IOException {
		// System.out.println(Common.PROCESSING + path);readSecretaryXls
		XSSFWorkbook xssfWorkbook = new XSSFWorkbook(stream);
		ImportBean importCourseBean = null;
		List<ImportBean> list = new ArrayList<ImportBean>();
		
		boolean flag=true;
		// Read the Sheet
		for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
			XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
			if (xssfSheet == null) {
				continue;
			}
			if(flag){
				// Read the Row
				for (int rowNum = 0; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
					XSSFRow xssfRow = xssfSheet.getRow(rowNum);
					if (xssfRow != null) {
						XSSFCell name = xssfRow.getCell(0);
						XSSFCell gender = xssfRow.getCell(1);
						XSSFCell certino = xssfRow.getCell(2);
						XSSFCell officePhone = xssfRow.getCell(3);
						XSSFCell phone = xssfRow.getCell(4);
						if(name==null){
							break;
						}
						if(rowNum==0){
							//验证导入的格式是否正确
							if(getValue(name).equals("姓名")&&getValue(gender).equals("性别")&&getValue(certino).equals("身份证号")&&getValue(officePhone).equals("办公电话")&&getValue(phone).equals("手机")){
								flag=true;
								continue;
							}else{
								flag=false;
								break;
							}
						}
						importCourseBean=new ImportBean();
						importCourseBean.setName(getValue(name));
						if(gender!=null){
							importCourseBean.setGender(getValue(gender));
						}
						if(certino!=null){
							importCourseBean.setCertino(getValue(certino));
						}
						if(officePhone!=null){
							importCourseBean.setOfficePhone(getValue(officePhone));
						}
						if(phone!=null){
							importCourseBean.setPhone(getValue(phone));
						}
						list.add(importCourseBean);
					}	
				}
			}
		}
		return list;
	}
	
	private List<ImportBean> readTeacherCourseXls(InputStream stream) throws IOException {
		HSSFWorkbook hssfWorkbook = new HSSFWorkbook(stream);
		ImportBean importCourseBean = null;
		List<ImportBean> list = new ArrayList<ImportBean>();
		boolean flag=true;
		// Read the Sheet
		for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
			HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
			if (hssfSheet == null) {
				continue;
			}
			// Read the Row
			if(flag){
				for (int rowNum = 0; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
					HSSFRow hssfRow = hssfSheet.getRow(rowNum);
					if (hssfRow != null) {
						HSSFCell name = hssfRow.getCell(0);
						HSSFCell courseCode = hssfRow.getCell(1);
						if(name==null||courseCode==null){
							break;
						}
						if(rowNum==0){
							//验证导入的格式是否正确
							if(getValue(name).equals("姓名")&&getValue(courseCode).equals("课程代码")){
								flag=true;
								continue;
							}else{
								flag=false;
								break;
							}
						}
						importCourseBean=new ImportBean();
						importCourseBean.setName(getValue(name));
						importCourseBean.setCourseCode(getValue(courseCode));
						list.add(importCourseBean);
					}
				}
			}
		}
		return list;
	}
	
	private List<ImportBean> readTeacherCourseXlsx(InputStream stream) throws IOException {
		XSSFWorkbook xssfWorkbook = new XSSFWorkbook(stream);
		ImportBean importCourseBean = null;
		List<ImportBean> list = new ArrayList<ImportBean>();
		
		boolean flag=true;
		// Read the Sheet
		for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
			XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
			if (xssfSheet == null) {
				continue;
			}
			if(flag){
				// Read the Row
				for (int rowNum = 0; rowNum <=xssfSheet.getLastRowNum(); rowNum++) {
					XSSFRow xssfRow = xssfSheet.getRow(rowNum);
					if (xssfRow != null) {
						XSSFCell name = xssfRow.getCell(0);
						XSSFCell courseCode = xssfRow.getCell(1);
						if(name==null||courseCode==null){
							break;
						}
						if(rowNum==0){
							//验证导入的格式是否正确
							if(getValue(name).equals("姓名")&&getValue(courseCode).equals("课程代码")){
								flag=true;
								continue;
							}else{
								flag=false;
								break;
							}
						}
						importCourseBean=new ImportBean();
						importCourseBean.setName(getValue(name));
						importCourseBean.setCourseCode(getValue(courseCode));
						list.add(importCourseBean);
					}	
				}
			}
		}
		return list;
	}
	
	private List<PaperTask> readPaperTaskXls(InputStream stream,JSONObject object) throws IOException {
		HSSFWorkbook hssfWorkbook = new HSSFWorkbook(stream);
		PaperTask paperTask = null;
		List<PaperTask> list = new ArrayList<PaperTask>();
		// Read the Sheet
		for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
			HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
			if (hssfSheet == null) {
				continue;
			}
			HSSFRow titleRow = hssfSheet.getRow(0);
			if(!"课程代码*".equals(getValue(titleRow.getCell(0)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 0) + "的标题名为：课程代码*");
				return null;
			}
			if(!"课程名称*".equals(getValue(titleRow.getCell(1)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 1) + "的标题名为：课程名称*");
				return null;
			}
			if(!"命题教师1*".equals(getValue(titleRow.getCell(2)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 2) + "的标题名为：命题教师1*");
				return null;
			}
			if(!"命题教师2*".equals(getValue(titleRow.getCell(3)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 3) + "的标题名为：命题教师2*");
				return null;
			}
			if(!"学科秘书1*".equals(getValue(titleRow.getCell(4)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 4) + "的标题名为：学科秘书1*");
				return null;
			}
//			if(!"学科秘书2*".equals(getValue(titleRow.getCell(5)))){
//				object.put("result", "fail");
//				object.put("lineNum",0);
//				object.put("msg", "请确保" + General.toExcelCoordinate(0, 5) + "的标题名为：学科秘书2*");
//				return null;
//			}
			if(!"排版员*".equals(getValue(titleRow.getCell(6)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 6) + "的标题名为：排版员*");
				return null;
			}
			// Read the Row
			for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
				HSSFRow hssfRow = hssfSheet.getRow(rowNum);
				if (hssfRow != null) {
					HSSFCell courseId = hssfRow.getCell(0);
					HSSFCell courseName = hssfRow.getCell(1);
					HSSFCell propositionTeacher = hssfRow.getCell(2);
					HSSFCell auditTeacher = hssfRow.getCell(3);
					HSSFCell primarySecretary = hssfRow.getCell(4);
					HSSFCell assistantSecretary = hssfRow.getCell(5);
					HSSFCell typeSetter = hssfRow.getCell(6);
					if(courseId==null||courseName==null||propositionTeacher==null||auditTeacher==null||primarySecretary==null||assistantSecretary==null||typeSetter==null){
						object.put("result", "fail");
						object.put("lineNum",rowNum);
						object.put("msg", "此行信息不完整");
						return null;
					}
					paperTask=new PaperTask(getValue(courseId),getValue(courseName),getValue(propositionTeacher),getValue(auditTeacher),getValue(typeSetter),getValue(primarySecretary),getValue(assistantSecretary));
					list.add(paperTask);
				}
			}
		}
		return list;
	}
	
	/**
	 * 解析试卷复审
	 * @param stream
	 * @param object
	 * @return
	 * @throws IOException
	 */
	private List<PaperTask> readReviewTaskXls(InputStream stream,JSONObject object) throws IOException {
		HSSFWorkbook hssfWorkbook = new HSSFWorkbook(stream);
		PaperTask paperTask = null;
		List<PaperTask> list = new ArrayList<PaperTask>();
		// Read the Sheet
		for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
			HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
			if (hssfSheet == null || hssfSheet.getLastRowNum() == 0) {
				continue;
			}
			HSSFRow titleRow = hssfSheet.getRow(0);
			if(!"试卷名称*".equals(getValue(titleRow.getCell(0)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 0) + "的标题名为：试卷名称*");
				return null;
			}
			if(!"命题教师*".equals(getValue(titleRow.getCell(1)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 1) + "的标题名为：命题教师*");
				return null;
			}
			if(!"学科秘书*".equals(getValue(titleRow.getCell(2)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 2) + "的标题名为：学科秘书*");
				return null;
			}
			if(!"排版员*".equals(getValue(titleRow.getCell(3)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 3) + "的标题名为：排版员*");
				return null;
			}
			// Read the Row
			for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
				HSSFRow hssfRow = hssfSheet.getRow(rowNum);
				if (hssfRow != null) {
					HSSFCell taskNo = hssfRow.getCell(0);
					HSSFCell auditTeacher = hssfRow.getCell(1);
					HSSFCell primarySecretary = hssfRow.getCell(2);
					HSSFCell typeSetter = hssfRow.getCell(3);
					if(taskNo == null|| auditTeacher == null|| primarySecretary == null || typeSetter == null){
						object.put("result", "fail");
						object.put("lineNum",rowNum);
						object.put("msg", "此行信息不完整");
						return null;
					}
					if(getValue(taskNo).length() != 14){
						object.put("result", "fail");
						object.put("lineNum",rowNum);
						object.put("msg", getValue(taskNo) + "命名不符合规范");
						return null;
					}
					paperTask=new PaperTask(getValue(taskNo),getValue(auditTeacher),getValue(primarySecretary),getValue(typeSetter));
					list.add(paperTask);
				}
			}
		}
		return list;
	}
	
	private List<AuditQuesTask> readAuditQuesTaskXls(InputStream stream,JSONObject object) throws IOException {
		HSSFWorkbook hssfWorkbook = new HSSFWorkbook(stream);
		List<AuditQuesTask> list = new ArrayList<AuditQuesTask>();
		// Read the Sheet
		for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
			HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
			if (hssfSheet == null) {
				continue;
			}
			HSSFRow titleRow = hssfSheet.getRow(0);
			if(!"课程代码*".equals(getValue(titleRow.getCell(0)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 0) + "的标题名为：课程代码*");
				return null;
			}
			if(!"课程名称*".equals(getValue(titleRow.getCell(1)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 1) + "的标题名为：课程名称*");
				return null;
			}
			if(!"审题教师列表*".equals(getValue(titleRow.getCell(2)))){
				object.put("result", "fail");
				object.put("lineNum",0);
				object.put("msg", "请确保" + General.toExcelCoordinate(0, 2) + "的标题名为：审题教师列表*");
				return null;
			}
			// Read the Row
			for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
				HSSFRow hssfRow = hssfSheet.getRow(rowNum);
				if (hssfRow != null) {
					HSSFCell courseId = hssfRow.getCell(0);
					HSSFCell courseName = hssfRow.getCell(1);
					HSSFCell auditors = hssfRow.getCell(2);
					if(courseId==null||courseName==null||auditors==null){
						object.put("result", "fail");
						object.put("lineNum",rowNum);
						object.put("msg", "此行信息不完整");
						return null;
					}
					AuditQuesTask task = new AuditQuesTask(getValue(courseId),getValue(courseName),getValue(auditors));
					list.add(task);
				}
			}
		}
		return list;
	}
	
	
	/**
	 * 读取2003版本的试卷启用excel
	 * @param stream
	 * @return
	 * @throws IOException
	 */
	private List<ImportBean> readStartedPaperXls(InputStream stream) throws IOException {
		HSSFWorkbook hssfWorkbook = new HSSFWorkbook(stream);
		ImportBean importBean = null;
		List<ImportBean> list = new ArrayList<ImportBean>();
		boolean flag=true;
		// Read the Sheet
		for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
			HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
			if (hssfSheet == null) {
				continue;
			}
			// Read the Row
			if(flag){
				for (int rowNum = 0; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
					HSSFRow hssfRow = hssfSheet.getRow(rowNum);
					if (hssfRow != null) {
						HSSFCell paperName = hssfRow.getCell(0);
						if(paperName==null){
							break;
						}

						String text = getValue(paperName);
						if(rowNum==0){
							//验证导入的格式是否正确
							if(text.equals("试卷编号") || text.toUpperCase().equals("SJBH")){
								flag=true;
								continue;
							}else{
								flag=false;
								break;
							}
						}
						importBean=new ImportBean();
						importBean.setName(text);
						list.add(importBean);
					}
				}
			}
		}
		return list;
	}
	
	/**
	 * 读取2007及以上版本的试卷启用excel
	 * @param stream
	 * @return
	 * @throws IOException
	 */
	private List<ImportBean> readStartedPaperXlsx(InputStream stream) throws IOException {
		// System.out.println(Common.PROCESSING + path);
		XSSFWorkbook xssfWorkbook = new XSSFWorkbook(stream);
		ImportBean importBean = null;
		List<ImportBean> list = new ArrayList<ImportBean>();
		boolean flag=true;
		// Read the Sheet
		for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
			XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
			if (xssfSheet == null) {
				continue;
			}
			if(flag){
				// Read the Row
				for (int rowNum = 0; rowNum <=xssfSheet.getLastRowNum(); rowNum++) {
					XSSFRow xssfRow = xssfSheet.getRow(rowNum);
					if (xssfRow != null) {
						XSSFCell paperName = xssfRow.getCell(0);
						if(paperName==null){
							break;
						}
						
						String text = getValue(paperName);
						if(rowNum==0){
							//验证导入的格式是否正确
							if(text.equals("试卷编号") || text.toUpperCase().equals("SJBH")){
								flag=true;
								continue;
							}else{
								flag=false;
								break;
							}
						}
						importBean=new ImportBean();
						importBean.setName(text);
						list.add(importBean);
					}	
				}
			}
		}
		return list;
	}
	
	private static String getValue(XSSFCell xssfRow) {
		if(null == xssfRow){
			return null;
		}
		if (xssfRow.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) {
			return String.valueOf(xssfRow.getBooleanCellValue()).replace("\u3000", " ").trim();
		} else if (xssfRow.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
			return General.formatDouble(xssfRow.getNumericCellValue()).replace("\u3000", " ").trim();
		} else {
			return String.valueOf(xssfRow.getStringCellValue()).replace("\u3000", " ").trim();
		}
	}

//	private Date getDateValue(XSSFCell xssfRow){
//		return xssfRow.getDateCellValue();
//	}
	
//	private Date getDateValue(HSSFCell hssfCell){
//		return hssfCell.getDateCellValue();
//	}
	
	private static String getValue(HSSFCell hssfCell) {
		if(hssfCell == null){
			return null;
		}
		if (hssfCell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN) {
			return String.valueOf(hssfCell.getBooleanCellValue()).replace("\u3000", " ").trim();
		} else if (hssfCell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
			return General.formatDouble(hssfCell.getNumericCellValue()).replace("\u3000", " ").trim();  
		} else {
			return String.valueOf(hssfCell.getStringCellValue()).replace("\u3000", " ").trim();  
		}
	}

//	private BigInteger getValue1(HSSFCell hssfCell) {
//		if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) {
//			BigDecimal bd = new BigDecimal(hssfCell.getNumericCellValue());
//			return bd.toBigInteger();
//		}
//		return null;
//	}
}
