Exemplo n.º 1
1
 public function upload_member_list()
 {
     $data['groupId'] = $this->input->post('groupId');
     // 把群組id放進去
     $config["encrypt_name"] = TRUE;
     $config['upload_path'] = './uploads/';
     $config['allowed_types'] = 'xls|xlsx|csv';
     //上傳文件格式
     $this->load->library('upload', $config);
     //讀取上傳的Lib
     if ($this->upload->do_upload()) {
         $arr = $this->upload->data();
     } else {
         $this->load->view('failure', array('message' => '新增成員失敗Q_Q..檔案副黨名必須為' . $config['allowed_types'], 'asideQuery' => $this->asideQuery, 'headerQuery' => $this->headerQuery));
         return false;
     }
     $this->load->library('PHPExcel');
     $this->load->library('PHPExcel/IOFactory');
     $reader = IOFactory::load("./uploads/{$arr['file_name']}");
     $sheet = $reader->getActiveSheet();
     $query = $this->member_model->select_all_account();
     // 先把所有帳號撈出來
     for ($i = 1; $i <= $sheet->getHighestRow(); $i++) {
         // 判斷所有帳號有沒有衝突到
         foreach ($query as $key => $value) {
             if ($value->account == $sheet->getCell('A' . $i)->getValue()) {
                 @unlink("./uploads/{$arr['file_name']}");
                 // 衝突到先把上傳的excel刪除
                 $this->load->view('failure', array('message' => '帳號' . $value->account . '已經存在,請確保excel內的帳號沒有衝突', 'asideQuery' => $this->asideQuery, 'headerQuery' => $this->headerQuery));
                 return false;
             }
         }
     }
     date_default_timezone_set("Asia/Taipei");
     //設定時區
     for ($i = 1; $i <= $sheet->getHighestRow(); $i++) {
         // 把每一筆excel的資料新增到SQL
         $data['account'] = $sheet->getCell('A' . $i)->getValue();
         $data['password'] = $sheet->getCell('B' . $i)->getValue();
         $data['name'] = $sheet->getCell('C' . $i)->getValue();
         $data['email'] = $sheet->getCell('D' . $i)->getValue();
         $data['createTime'] = date("Y-m-d H:i:s", time());
         //把時間放進欄位
         $this->member_model->insert_data($data);
     }
     @unlink("./uploads/{$arr['file_name']}");
     $this->load->view('success', array('message' => '新增成員成功^_^', 'redirectUrl' => 'member', 'asideQuery' => $this->asideQuery, 'headerQuery' => $this->headerQuery));
     return true;
     // $this->load->view('')
 }
Exemplo n.º 2
0
 public function getContent($file)
 {
     $writer = new HTML(@IOFactory::load($file));
     $html = $writer->getContent();
     // Remove <style> manually
     $html = preg_replace('/<style>.*<\\/style>/s', '', $html);
     // Remove HTML tags
     return strip_tags($html);
 }
 /**
  * Load document
  */
 public function testLoad()
 {
     $file = __DIR__ . '/_files/templates/blank.docx';
     $this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', IOFactory::load($file));
 }
Exemplo n.º 4
0
 function setExcelSchedule($file)
 {
     $this->load->library('PHPExcel');
     $this->load->library('PHPExcel/IOFactory');
     if (substr(strrchr($file['orig_name'], '.'), 1) == 'xlsx') {
         $excel = IOFactory::load($file['full_path']);
         $num = 0;
         foreach ($excel->getWorksheetIterator() as $worksheet) {
             if ($num == 0) {
                 // first worksheet only
                 $letterColumn = $worksheet->getHighestColumn();
                 $numColumn = Cell::columnIndexFromString($letterColumn);
                 $numRow = $worksheet->getHighestRow();
                 $classes = array();
                 for ($row = 2; $row <= $numRow; $row++) {
                     //start at second row
                     $rowData = array();
                     for ($col = 0; $col < $numColumn; $col++) {
                         $cell = $worksheet->getCellByColumnAndRow($col, $row);
                         $val = $cell->getValue();
                         array_push($rowData, $val);
                     }
                     array_push($classes, $rowData);
                 }
             }
             $num++;
         }
         $post = $this->input->post();
         $schedule = array('year' => $post['year'], 'semester' => $post['semester'], 'classes' => $classes);
         $this->setSchedule($schedule);
     }
 }