package com.quant.comm;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import jxl.Sheet;
import jxl.Workbook;
import com.quant.vo.ExcelVo;

public class StuService {
	private static int rows;
	
	public static int getRows() {
		return rows;
	}	
	public static List<ExcelVo> getAllByExcel(String file,String sheetName,boolean flag)throws Exception{
		List<ExcelVo> list=new ArrayList<ExcelVo>();
		if(flag){
			try {
				Workbook rwb=Workbook.getWorkbook(new File(file));
				
				Sheet rs=rwb.getSheet(sheetName);
				int clos=rs.getColumns();
				rows=rs.getRows();
				for (int i = 1; i < rows; i++) {
					for (int j = 0; j < clos; j++) {
							ExcelVo excelVo = new ExcelVo();
							excelVo.setIndex(j);
							excelVo.setValue(rs.getCell(j,i).getContents());
							list.add(excelVo);
					}
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
			
		}else{
			try {
				Workbook rwb=Workbook.getWorkbook(new File(file));
				Sheet rs=rwb.getSheet(sheetName);
				int clos=rs.getColumns();
				rows=rs.getRows();
					for (int j = 0; j < clos; j++) {
							ExcelVo excelVo = new ExcelVo();
							excelVo.setIndex(j);
							excelVo.setValue(rs.getCell(j,0).getContents());
							list.add(excelVo);
					}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		}
		return list;
	}
	
	
	
	}
	

