導入Excel數據

import java.io.IOException;
import java.io.InputStream;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;java

import com.zhq.web.daos.Students;web

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;spring

public class JxlImpl extends HibernateDaoSupport implements Jxl {ide

 public JxlImpl() {
    }
 
 @Override
 public int importStudent(InputStream is) {
  
   int flag = 0;
         int rows = 0; //表單行數  
         Sheet sh = null; //表單對象  
         //InputStream inputStream = null;  
         Workbook book = null;
         try {
    book = Workbook.getWorkbook(is);
   } catch (BiffException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }  
            sh = book.getSheet(0);  
            rows = sh.getRows();  
           
            String s=null;
            s=sh.getCell(0,0).getContents();
       
        
            for(int i=1;i<rows;i++){
       
          Students ss=new Students();
    ss.setName(new String(sh.getCell(0,i).getContents()));
    ss.setNo(new String(sh.getCell(1,i).getContents()));
    ss.setPassword(new String(sh.getCell(2,i).getContents()));
    ss.setSex(new String(sh.getCell(3,i).getContents()));
    this.getHibernateTemplate().save(ss);
          flag=1;
          }
           
          return flag;
 }this

}
hibernate

相關文章
相關標籤/搜索