2012年9月27日 星期四

php excel

EXCEL讀檔 寫入MYSQL

include_once("../XXX/phpexcel/PHPExcel/IOFactory.php");
include_once('../XXX/phpexcel/PHPExcel/Reader/Excel5.php');
 if($_FILES['employeeData']['name']=="" )"ERROR!!no FILE!!";

 $reader = new PHPExcel_Reader_Excel5;
 $PHPExcel=$reader->load($_FILES['exployxeData']['tmp_name']);
 $sheet=$PHPExcel->getSheet(0);
 $highestRow=$sheet->getHighestRow();

for($row=1;$row<=$highestRow;$row++){
 //echo $i."$$";
 $str='';
  for($column=0;$column<=6;$column++){
   $aa=$sheet->getCellByColumnAndRow($column,$row)->getvalue();
    $temp[$column]=$aa;
    if($column=='0'){
     $str.="'".$aa."',";//id
     $str.="'".$aa."',";//pwd
    }elseif($column=='6'){
     if($temp[4]==$temp[0]){
      $str.="'1',";   
     }elseif($temp[6]=='1'){
      $str.="'2',";
     }else{
      $str.="'0',";
     }
     
    
    }elseif($column=='5'){
     continue;
    }else{
     if($aa!=''){
      $str.="'".$aa."',";
     }
    }
   
  }
   
   $str=substr($str,0,strlen($str)-1);
   
   
  if($row>1){
   $sql="insert into Base  (`ID`,`Pwd`,`Name`,`Name`,`Email`,`lID`,`role`)values($str)";
   mysql_query($sql);
   
   if(! mysql_affected_rows()>0){
    echo "error:name:{$temp[1]}";
    exit;
   }
  }
 }

寫入excel
include_once("../class/phpexcel/PHPExcel/IOFactory.php");

$path="../download/";
 $objRD=PHPExcel_IOFactory::createReader("Excel5");
 
 $objExcel=$objRD->load($path."temp.xls");
 //$CobjExcel=new PHPExcel();

 //$objExcel=$CobjExcel->load($path."temp.xls");
 
 $objExcel->setActiveSheetIndex(0);
 $sheet=$objExcel->getActiveSheet();

 for($i=1;$i<$num;$i++){
  //if($data[$i]['enable']==0) continue; #因為sql裡面排除不了enable為0的,所以做此處理
         $sheet->setCellValueByColumnAndRow(0,$colum,$searchContent[$i]['userName']);
  $sheet->setCellValueByColumnAndRow(1,$colum,$searchContent[$i]['ID']);           
  $sheet->setCellValueByColumnAndRow(2,$colum,$searchContent[$i]['shifName']);
$colum++;
  }
  
  
  $objExcel=PHPExcel_IOFactory::createWriter($objExcel,'Excel5');

  $filePath=$path."labor_hour.xls";
  $objExcel->save($filePath);
  
  
  dl_file($filePath);  

2012年9月24日 星期一

關閉視窗

<script type='text/javascript'>

function windows_close(){
 window.open('','_parent','');  
 window.opener = null;
 window.open('','_parent','');
 window.close();
}
</script>

<input type='button' onclick='windows_close()' value='關閉視窗'>
ex-2
<script type='text/javascript'>
 function doClose(){this.close();}
</script>

2012年9月18日 星期二

javascript 時間

時間:
建立Date 物件
today=new Date();
//出來的是 Wed Sep 19 2012 14:41:42 GMT+0800(台北標準時間)

Date的三種用法
物件名稱=new Date()
物件名稱=new Date("月 日,年 時:分:秒");
物件名稱=new Date (年,月,日,時,分,秒);

使用物件的方法
取得
getYear()
getMonth()
getDate()
getDay()
getHours()
getMinutes()
getSeconds()
設定
setYear()
setMonth();
setDate();
setHours();
setMinutes();
setSeconds();

today.getTime();
出來的是unix的秒數