public function main($UrlAppend = NULL, $get = NULL, $post = NULL) { if ($this->_isPost()) { $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('utf-8'); $file = $this->_upload(); $data->read($file["path"]); $keyArr = array(); for ($a = 1; $a < 1000; $a++) { if ($data->sheets[0]['cells'][1][$a] != "") { array_push($keyArr, $data->sheets[0]['cells'][1][$a]); } } $dataList = array(); for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) { $valueArr = array(); for ($b = 0; $b < count($keyArr); $b++) { if ($keyArr[$b] == "key") { $key = $data->sheets[0]['cells'][$i][$b + 1]; } else { $valueArr[$keyArr[$b]] = $data->sheets[0]['cells'][$i][$b + 1]; } } $dataList[$key] = $valueArr; } $this->_f($_POST["FileName"], $dataList); } return $this->_assign; }
function getAll() { $reader = new Spreadsheet_Excel_Reader(); $reader->setUTFEncoder('iconv'); $reader->setOutputEncoding('UTF-8'); $reader->read($this->filename); $data = array(); $index_row = 1; if ($this->have_header) { $index_row = 2; } $iterator = -1; for ($i = $index_row; $i <= $reader->sheets[$this->sheet_index]['numRows']; $i++) { $iterator++; $data[$iterator] = array(); for ($j = 1; $j <= $reader->sheets[$this->sheet_index]['numCols']; $j++) { if ($this->have_header) { $data[$iterator][$this->headers[$j - 1]] = $reader->sheets[0]['cells'][$i][$j]; } else { $data[$iterator][$j - 1] = $reader->sheets[0]['cells'][$i][$j]; } } } return $data; }
function ABSSAV() { $inFile = $_REQUEST['inFile']; echo "Filename is: {$inFile}<br>"; require_once 'Excel/reader.php'; $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('CP1251'); $data->read($inFile); error_reporting(E_ALL ^ E_NOTICE); $Target_Database = 'binawan'; $Target_Table = $Target_Database . '.ruang'; $Target_KodeID = "BINAWAN"; $s = "TRUNCATE TABLE {$Target_Table}"; $r = _query($s); for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) { $w = array(); $w['RuangID'] = trim($data->sheets[0]['cells'][$i][2]); $w['Nama'] = trim($data->sheets[0]['cells'][$i][3]); $w['Kapasitas'] = trim($data->sheets[0]['cells'][$i][4]); $w['KapasitasUjian'] = trim($data->sheets[0]['cells'][$i][4]); $w['KolomUjian'] = trim($data->sheets[0]['cells'][$i][5]); $w['KampusID'] = trim($data->sheets[0]['cells'][$i][6]); $w['Lantai'] = trim($data->sheets[0]['cells'][$i][7]); $w['RuangKuliah'] = trim($data->sheets[0]['cells'][$i][8]); $s = "insert into {$Target_Table}\r\n (RuangID, Nama, Kapasitas, KapasitasUjian, KolomUjian, KampusID, Lantai, KodeID, RuangKuliah, UntukUSM\r\n\t )\r\n values\r\n ('{$w['RuangID']}', '{$w['Nama']}', '{$w['Kapasitas']}', '{$w['KapasitasUjian']}', '{$w['KolomUjian']}', '{$w['KampusID']}', '{$w['Lantai']}', 'BINAWAN', '{$w['RuangKuliah']}', '{$w['RuangKuliah']}'\r\n\t )"; $r = _query($s); } echo "<script>window.location = '?{$mnux}={$_SESSION['mnux']}'</script>"; }
/** Helper for xls files. See fileToArray() */ public static function xlsToArray($filename, $limit) { if (!class_exists('Spreadsheet_Excel_Reader')) { include_once dirname(__FILE__) . '/../../src/Excel/xls_read/reader.php'; } $data = new \Spreadsheet_Excel_Reader(); $data->setOutputEncoding('ISO-8859-1'); $data->read($filename); $sheet = $data->sheets[0]; $rows = $sheet['numRows']; $cols = $sheet['numCols']; $ret = array(); for ($i = 1; $i <= $rows; $i++) { $line = array(); for ($j = 1; $j <= $cols; $j++) { if (isset($sheet['cells'][$i]) && isset($sheet['cells'][$i][$j])) { $line[] = $sheet['cells'][$i][$j]; } else { $line[] = ''; } } $ret[] = $line; if ($limit != 0 && count($ret) >= $limit) { break; } } return $ret; }
function updateDB($startIndex, $endIndex) { //need to copy the code that does the excel reading $analysisData = new Spreadsheet_Excel_Reader(); // Set output Encoding. $analysisData->setOutputEncoding('CP1251'); $inputFileName = 'ReverseGeoCodingForStopsVerification.xls'; $analysisData->read($inputFileName); error_reporting(E_ALL ^ E_NOTICE); $numRows = $analysisData->sheets[0]['numRows']; $numCols = $analysisData->sheets[0]['numCols']; //echo $numRows.",".$numCols; $strRoute = '<Routes>'; for ($i = $startIndex; $i <= $endIndex; $i++) { $stopId = $analysisData->sheets[0]['cells'][$i][1]; $StopName = $analysisData->sheets[0]['cells'][$i][2]; $Buses = $analysisData->sheets[0]['cells'][$i][3]; $latitude = $analysisData->sheets[0]['cells'][$i][4]; $longitude = $analysisData->sheets[0]['cells'][$i][5]; $strRoute = $strRoute . '<Route>'; $routeDetails = htmlentities(trim($StopName)) . ":" . $latitude . ":" . $longitude; //echo $routeDetails."<br/>"; $strRoute = $strRoute . '<RouteDetails>' . $routeDetails . '</RouteDetails>'; $strRoute = $strRoute . '</Route>'; } $strRoute = $strRoute . '</Routes>'; echo $strRoute; }
public function localUploadSNExcel() { $return = $this->localUpload(array('xls')); if ($return['error']) { $this->error($return['msg']); } else { $data = new Spreadsheet_Excel_Reader(); // 设置输入编码 UTF-8/GB2312/CP936等等 $data->setOutputEncoding('UTF-8'); $data->read(str_replace('http://' . $_SERVER['HTTP_HOST'], $_SERVER['DOCUMENT_ROOT'], $return['msg'])); chmod(str_replace('http://' . $_SERVER['HTTP_HOST'], $_SERVER['DOCUMENT_ROOT'], $return['msg']), 0777); // $sheet = $data->sheets[0]; $rows = $sheet['cells']; if ($rows) { $i = 0; foreach ($rows as $r) { if ($i != 0) { $db = M('Lottery_record'); $where = array('token' => $this->token, 'lid' => intval($_POST['lid']), 'sn' => trim($r[1])); $check = $db->where($where)->find(); if (!$check) { $where['prize'] = intval($r['2']); $db->add($where); } } $i++; } } $this->success('操作完成'); } }
function ABSSAV() { $inFile = $_REQUEST['inFile']; require_once 'Excel/reader.php'; $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('CP1251'); $data->read($inFile); error_reporting(E_ALL ^ E_NOTICE); $Target_Database = 'binawan'; $Target_Table = $Target_Database . 'mhsw'; $Target_KodeID = "BINAWAN"; $s = "TRUNCATE TABLE "; $r = _query($s); for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) { $w = array(); $w['MhswID'] = trim($data->sheets[0]['cells'][$i][1]); $w['TahunID'] = trim($data->sheets[0]['cells'][$i][2]); $w['Nama'] = trim($data->sheets[0]['cells'][$i][3]); $w['Kelamin'] = trim($data->sheets[0]['cells'][$i][4]); $w['TempatLahir'] = trim($data->sheets[0]['cells'][$i][5]); $w['TanggalLahir'] = trim($data->sheets[0]['cells'][$i][6]); $w['Agama'] = trim($data->sheets[0]['cells'][$i][7]); $w['Alamat'] = trim($data->sheets[0]['cells'][$i][8]); $s = "insert into {$Target_Database}\r\n (MhswID, Login, LevelID, Password, PMBID, \r\n\t\t TahunID, KodeID, Nama, \r\n\t\t Foto, StatusMhswID, ProgramID, ProdiID, KelasID,\r\n\t\t Kelamin, TempatLahir, TanggalLahir, Agama, Alamat, \r\n\t\t Kota, RT, RW, KodePos, Propinsi, Negara, \r\n\t\t Telepon, Handphone \r\n\t )\r\n values\r\n ('{$w['MhswID']}', '{$w['Login']}', '120', '{$w['Password']}', '{$w['PMBID']}', \r\n\t\t '{$w['TahunID']}', '{$Target_KodeID}', '{$w['Nama']}', \r\n\t\t '{$w['Foto']}', '{$w['StatusMhswID']}', '{$w['ProgramID']}', '{$w['ProdiID']}', '{$w['KelasID']}',\r\n\t\t '{$w['Kelamin']}', '{$w['TempatLahir']}', '{$w['TanggalLahir']}', '{$w['Agama']}', '{$w['Alamat']}', \r\n\t\t '{$w['Kota']}', '{$w['RT']}', '{$w['RW']}', '{$w['KodePos']}', '{$w['Propinsi']}', '{$w['Negara']}', \r\n\t\t '{$w['Telepon']}', '{$w['Handphone']}' \r\n\t )"; $r = _query($s); } echo "<script>window.location = '?{$mnux}={$_SESSION['mnux']}'</script>"; }
public function add_in_mysql() { if (!empty($_FILES['efile']['name'])) { $exname = strtolower(substr($_FILES['efile']['name'], strrpos($_FILES['efile']['name'], '.') + 1)); $uploadfile = $this->getnames($exname); //上传后文件所在的路径 @move_uploaded_file($_FILES['efile']['tmp_name'], $uploadfile); } $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('utf-8'); $data->read($uploadfile); //读取要导入数据库的文件 error_reporting(E_ALL ^ E_NOTICE); $Stu = D("Stu"); //$User->startTrans();//启动事务; $filed = C("excle"); //获取字段对应的列 for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) { $col = $data->sheets[0]['cells'][$i]; $arr = array("stuno" => $col[$filed["stuno"]], "stuname" => $col[$filed["stuname"]], "password" => $col[$filed["password"]], "sex" => $col[$filed["sex"]], "idcard" => $col[$filed["idcard"]], "classno" => $col[$filed["classno"]], "college" => "1"); $Stu->create($arr); echo $Stu->getError() . "<br/>"; if (!$Stu->add()) { $Stu->rollback(); //不成功,回滚 echo "导入失败回滚"; return; } echo $arr["stuno"] . "导入成功<br/>"; } $Stu->commit(); //成功提交 }
function doimport() { $file_name = $_GET['province_id'] . ".xls"; if ($file_name != '') { //$ext = pathinfo($_FILES['filename']['name'], PATHINFO_EXTENSION); //echo $file_name = 'nursery.'.$ext; $uploaddir = 'import/tmp/'; $fpicname = $uploaddir . $file_name; ///move_uploaded_file($_FILES['filename']['tmp_name'], $fpicname); require_once 'include/Excel/reader.php'; $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('UTF-8'); $data->read($fpicname); error_reporting(E_ALL ^ E_NOTICE); $index = 0; for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) { $amphur = new Amphur(); $amphur = $amphur->where(" amphur_name ='" . trim($data->sheets[0]['cells'][$i][1]) . "'")->get(); $import[$index]['province_id'] = $_POST['province_id']; $import[$index]['amphur_id'] = $amphur->id; $import[$index]['name'] = trim($data->sheets[0]['cells'][$i][2]); $index++; if ($amphur->id > 0) { $_POST['province_id'] = $_GET['province_id']; $_POST['amphur_id'] = $amphur->id; $_POST['name'] = trim($data->sheets[0]['cells'][$i][2]); $nursery = new Nursery_Tmp(); $nursery->from_array($_POST); $nursery->save(); } } } }
function readRoom($file, $table, $pos) { require_once "conn.php"; $sql = "TRUNCATE TABLE {$table}"; if ($mysqliObj->query($sql)) { echo "truncate success" . "</br>"; } require_once 'Excel/reader.php'; // ExcelFile($filename, $encoding); $data = new Spreadsheet_Excel_Reader(); // Set output Encoding. // $data->setOutputEncoding('CP936'); $data->setOutputEncoding('gbk'); $data->read($file); error_reporting(E_ALL ^ E_NOTICE); //$data->sheets[0]['numRows'] for ($i = $pos; $i <= $data->sheets[0]['numRows']; $i++) { $msg1 = $data->sheets[0]['cells'][$i][1]; $msg2 = $data->sheets[0]['cells'][$i][2]; $msg3 = $data->sheets[0]['cells'][$i][3]; $sql = "INSERT INTO {$table} (`roomId` ,`type` ,`price` )\n\t\t\t\tVALUES ('{$msg1}', '{$msg2}', '{$msg3}')"; if (!is_null($data->sheets[0]['cells'][$i][1])) { $mysqliObj->query($sql); } } $mysqliObj->close(); }
function do_upload() { $config['upload_path'] = './upload/'; $config['allowed_types'] = 'php|txt|xls|xml'; $config['max_size'] = '1000000'; //$config['max_width'] = '1024'; //$config['max_height'] = '768'; $this->load->library('upload', $config); if (!$this->upload->do_upload()) { $error = array('error' => $this->upload->display_errors()); //$this->load->view('header'); $this->load->view('upload_view', $error); //$this->load->view('footer'); } else { $data = array('upload_data' => $this->upload->data()); $this->load->library('Excel/spreadsheet_Excel_Reader'); //require_once 'Excel/reader.php'; // ExcelFile($filename, $encoding); $excel = new Spreadsheet_Excel_Reader(); // Set output Encoding. $excel->setOutputEncoding('CP1251'); //lecture du fichier excel //chmod('./upload/' . $data['upload_data']['file_name'], 0777); $excel->read('./upload/' . $data['upload_data']['file_name']); //$liste = array($excel->sheets[0]['numRows'],2); $array = $excel->sheets[0]['cells']; $temp = array_shift($array); var_dump($array); //$this->data_model->insert_entry($array); $this->load->view('upload_success', $data); } }
function popola($file, $id_associazione) { $data = new Spreadsheet_Excel_Reader(); //$data->setOutputEncoding('CP1251'); //UTF-8 $data->setOutputEncoding('UTF-8'); $data->read($file); error_reporting(E_ALL ^ E_NOTICE); $counter = 0; $counterP = 0; $log_error = new log(); for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) { $counterP++; echo $counterP . " "; if ($counterP % 100 == 0) { echo "\n Processati: " . $counterP . "\n"; } ob_flush(); flush(); $query = "INSERT into soci (nome,mail) values "; $query .= "("; echo $data->sheets[0]['cells'][$i][1] . " ... \n"; $actual_element = trim($data->sheets[0]['cells'][$i][1], " \t\n\r\v,;"); echo $actual_element; $actual_element = mysql_real_escape_string($actual_element); $actual_element2 = trim($data->sheets[0]['cells'][$i][2], " \t\n\r\v,;"); $mail = mysql_real_escape_string($actual_element2); $query .= "'" . $actual_element . "','" . $mail . "'"; // Aggiungi user e password //$query.="'".(($email=="") ? getUniqueCode(10) : $email)."','".getUniqueCode(10)."',$id_associazione"; $query .= ")"; //validate email if (!Swift_Validate::email($actual_element2)) { //validate email, log error $log_error->scrivi_popola($actual_element . "\t" . $mail); } else { //insert into DB $result = mysql_query("SELECT id FROM soci WHERE mail='" . $mail . "'"); if ($riga = mysql_fetch_assoc($result)) { //if the mail is already in the database $int_id = $riga['id']; } else { if (!mysql_query($query)) { //insert new record echo "ti è andata male "; echo $query; return false; } $int_id = mysql_insert_id(); $counter++; } if ($id_associazione > 0) { mysql_query("INSERT into interessi_soci (id_socio,id_interesse) values ('{$int_id}','{$id_associazione}')"); } } } $log_error->close_popola(); //return $data->sheets[0]['numRows']-1; return "<BR>Letti " . $counterP . " e inseriti (non duplicati) " . $counter; }
function get_student_schedule($filename, $teacherSchedule) { $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('UTF8'); $data->setUTFEncoder('mb'); $data->read($filename); return get_result_student($data, $teacherSchedule); }
function readxlsmain($file) { $d = new Spreadsheet_Excel_Reader(); $d->setOutputEncoding('utf-8'); $d->read($file); $data = array(); $data['boundsheets'] =& $d->boundsheets; $data['sheets'] =& $d->sheets; return $data; }
function process_file($filename, &$tempname) { global $_SGLOBAL; $isfile = 1; $data = new Spreadsheet_Excel_Reader(); //exit('adsf'); $data->setOutputEncoding('gbk'); $data->read($filename); $tempname = date("Y-m-d") . '_download_' . rand() . '.xls'; $filedownload = S_ROOT . './plugin/invite/download/' . $tempname; //初始化一个反馈结果的文件 require_once S_ROOT . './plugin/invite/phpwritexcel/Writer.php'; $workbook = new Spreadsheet_Excel_Writer($filedownload); $worksheet =& $workbook->addWorksheet('Sheet1'); $worksheet->setInputEncoding('utf-8'); $format_column =& $workbook->addformat(array('Size' => 9, 'Bold' => 1)); //读取结果文件的信息 $rows = 0; $recordindex = array('realname', 'sex', 'birthday', 'otheremail', 'academy', 'collegeid', 'class', 'mobile', 'unit'); $record = array('好友姓名(必填)', '好友性别', '生日(8位)', '邮箱(必填)', '学院', '学号', '班别', '手机(必填)', '所在单位', '备注'); $dataindexinfo = array(); encode_record(&$record); input_downloadfile($worksheet, $rows, $record, $format_column); for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) { //以下注释的for循环打印excel表数据 $datainfo = array(); //$datainfo = array('name', 'sex', 'birthday', 'otheremail', 'academy', 'collegeid', 'class', 'mobile', 'unit'); for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) { $datainfo[$j - 1] = $data->sheets[0]['cells'][$i][$j]; $dataindexinfo[$recordindex[$j - 1]] = $data->sheets[0]['cells'][$i][$j]; } //var_dump($datainfo[0]); //检查记录的正确性 $nopass = checkinfo($datainfo[0], $datainfo[2], $datainfo[3], $datainfo[7], $isfile); if (!empty($nopass)) { //没有通过的记录加入到一个新文件中 $datainfo[$j - 1] = $nopass; encode_record(&$datainfo); //var_dump($datainfo); //var_dump($rows); input_downloadfile($worksheet, &$rows, $datainfo, $format_column); continue; } //邀请处理 //var_dump($dataindexinfo); inserttable('baseprofile', $dataindexinfo, 1); //var_dump($datainfo); invite_alumni($datainfo); } $workbook->close(); return $rows; }
public function _batchDeal() { $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('utf-8'); $file = $this->_upload(); $data->read($file["path"]); for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) { $sendData = array('WorldID' => intval($data->sheets[0]['cells'][$i][1]), 'IsAllPlayer' => intval(0), 'PlayerID' => trim($data->sheets[0]['cells'][$i][2]), 'Title' => trim($data->sheets[0]['cells'][$i][3]), 'Content' => trim($data->sheets[0]['cells'][$i][4]), 'IsPack' => intval($data->sheets[0]['cells'][$i][5]), 'ItemID' => intval($data->sheets[0]['cells'][$i][6]), 'ItemNum' => intval($data->sheets[0]['cells'][$i][7]), 'IsBinded' => intval($data->sheets[0]['cells'][$i][8]), 'TimeDurableType' => intval($data->sheets[0]['cells'][$i][9]), 'TimeDurable' => intval(strtotime($data->sheets[0]['cells'][$i][10])), 'ImproveLevel' => intval($data->sheets[0]['cells'][$i][11]), 'AttachAttribute' => trim($data->sheets[0]['cells'][$i][12]), 'Money' => trim($data->sheets[0]['cells'][$i][13]), 'Exp' => intval($data->sheets[0]['cells'][$i][14])); $returnData .= "[" . $i . "]" . $this->addApply($sendData) . "<br/>"; } $URL_CsIndex = Tools::url('Apply', 'CsIndex'); $URL_CsAll = Tools::url('Apply', 'CsAll'); $showMsg = $returnData; $showMsg .= "<a href='{$URL_CsIndex}'>客服审核列表</a><br>"; $showMsg .= "<a href='{$URL_CsAll}'>客服审核列表(全部)</a>"; $this->jump($showMsg, 1, 1, false); die($returnData); }
public static function readXLS($file) { $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('UTF-8'); //设置输出的编码为utf8 $ret = $data->read($file); //要读取的excel文件地址 if ($ret == -1) { $array = false; } else { for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) { for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) { $array[$i - 1][$j - 1] = $data->sheets[0]['cells'][$i][$j]; } } } return $array; }
public static function leerMarcadoresExcel($fichero) { $leidos = array(); $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('CP1251'); $data->read($fichero); //Se comienza de indice 2 para un excel donde la primera row sea los titulos de las columnas for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) { $objeto = new Marcador(); $objeto->lat = $data->sheets[0]['cells'][$i][1]; $objeto->lng = $data->sheets[0]['cells'][$i][2]; $objeto->nombre = $data->sheets[0]['cells'][$i][3]; $objeto->direccion = $data->sheets[0]['cells'][$i][4]; $objeto->codPostal = $data->sheets[0]['cells'][$i][5]; array_push($leidos, $objeto); } return $leidos; }
function _fallbackExcelReader($sFilename, $sTempFilename) { require_once KT_DIR . '/thirdparty/excelreader/Excel/reader.php'; $reader = new Spreadsheet_Excel_Reader(); $reader->setOutputEncoding('UTF-8'); $reader->read($sFilename); $t = fopen($sTempFilename, "w"); foreach ($reader->sheets as $aSheet) { for ($i = 1; $i <= $aSheet['numRows'] && $i <= 1000; $i++) { for ($j = 1; $j <= $aSheet['numCols'] && $j <= 1000; $j++) { fwrite($t, $aSheet['cells'][$i][$j] . " "); } fwrite($t, "\n"); } fwrite($t, "\n\n\n"); } fclose($t); return file_get_contents($sTempFilename); }
public function dealExcel($file) { include BASE_DATA_PATH . "/Excel/reader.php"; $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('GBK'); $data->read($file); $xls_arr = array(); for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) { for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) { $val = iconv("gb2312", "utf-8//IGNORE", $data->sheets[0]['cells'][$i][$j]); $xls_arr[$i][$j] = $val; } echo "\n"; } if (!empty($xls_arr)) { return $this->insertExcelData($xls_arr); } else { return true; } }
public static function parseexcel($filepath, $source = 'GBK', $target = 'UTF-8') { $data = array(); require PATH_APPLICATION . '/pm_excel_reader.class.php'; $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('GBK'); @$data->read($filepath); $dataarray = array(); for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) { for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) { $dataarray[$i][$j] = $data->sheets[0]['cells'][$i][$j]; } } if ($source == $target) { $data = array_slice($dataarray, 1); } else { $dataarray = ck_iconv_deep($source, $target, $dataarray); $data = array_slice($dataarray, 1); } return $data; }
function reader_excel($destination, $phonebook_id) { // Set output Encoding. $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('utf-8'); //”data.xls”是指要导入到mysql中的excel文件 $data->read($destination); echo $phonebook_id; echo '<br/>'; echo "<table style='border-collapse:collapse;border-spacing:0;border:1px solid #000'>"; for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) { //以下注释的for循环打印excel表数据 $array = array(); $contacts_arr = array(); echo "<tr style='border:1px solid #000'>"; for ($j = 1; $j <= 3; $j++) { if (empty($data->sheets[0]['cells'][$i][$j])) { $array[$j - 1] = null; echo "<td style='border:1px solid #000'></td>"; } else { $array[$j - 1] = $data->sheets[0]['cells'][$i][$j]; echo "<td style='border:1px solid #000'>" . $data->sheets[0]['cells'][$i][$j] . "</td>"; } } echo '</tr>'; var_dump($array); echo '<br/>'; $sql_fetchlongnum = "SELECT * FROM contacts where longnum ='{$array[1]}'"; $old_phonebook_id = fetchOne($sql_fetchlongnum)['phonebook_id']; if ($old_phonebook_id) { $new_phonebook_id = $old_phonebook_id . '|' . $phonebook_id; $contacts_arr = array('phonebook_id' => $new_phonebook_id); update('contacts', $contacts_arr, "longnum=" . "'{$array['1']}'"); } else { $contacts_arr = array('phonebook_id' => $phonebook_id, 'name' => $array[0], 'longnum' => $array[1], 'shortnum' => $array[2]); echo insert('contacts', $contacts_arr); } } echo "</table>"; }
function TestBackupExcel() { $filename = 'products_test.xls'; $this->p_ex->DownloadIdMot = 1; // We will create file with articles, that are connected with id_mot=1 $this->p_ex->DownloadRubriques = array(1); // We will create file with articles, that lie in rubrique 1 $this->p_ex->BackupExcel($filename); $full_path = $this->p_ex->GetTmpDir() . $filename; $this->assertTrue(file_exists($full_path), 'Excel file hasn\'t been created!'); $reader = new Spreadsheet_Excel_Reader(); $reader->setUTFEncoder('iconv'); $reader->setOutputEncoding('UTF-8'); $reader->read($full_path); $this->assertEqual(1, count($reader->sheets)); // Document must contain 1 sheet $rows = $reader->sheets[0]["cells"]; $this->assertEqual(3, count($rows)); // Document must contain 1 heading + 1 data = 2 rows if (file_exists($full_path)) { unlink($full_path); } }
function uploadScore($exam_paper) { $this->exam->id = $exam_paper; if ($this->input->post('submit')) { try { if ($_FILES['score_table']['error'] > 0) { throw new Exception('文件上错错误:错误代码: ' . $_FILES['score_table']['error']); } if (!(preg_match('/\\.(\\w*?)$/', $_FILES['score']['name'], $extname_match) && $extname_match[1] == 'xls')) { throw new Exception('文件格式错误,请上传xls格式的excel表格'); } require APPPATH . 'third_party/PHP-ExcelReader/reader.php'; $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('utf-8'); $data->setRowColOffset(0); $data->read($_FILES['score']['tmp_name']); $this->exam->uploadScore($data); } catch (Exception $e) { $this->output->message($e->getMessage(), 'warning'); } } $this->load->view('exam/uploadscore'); }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php error_reporting(E_ALL ^ E_NOTICE); require_once 'Excel/reader.php'; // ExcelFile($filename, $encoding); $data = new Spreadsheet_Excel_Reader(); // Set output Encoding. $data->setOutputEncoding('utf-8'); //$data->read($filepath.$filename); //$data->read("test1.xls"); $data->read($file_path); $list_result = $data->sheets[0]['cells']; //导入的excel表格的第一个shell数据结果 ?> </body> </html>
/** * Handles a given Excel spreadsheets as in the template provided */ function lp_upload_quiz_action_handling() { global $debug; $_course = api_get_course_info(); $courseId = $_course['real_id']; if (!isset($_POST['submit_upload_quiz'])) { return; } // Get the extension of the document. $path_info = pathinfo($_FILES['user_upload_quiz']['name']); // Check if the document is an Excel document if ($path_info['extension'] != 'xls') { return; } // Read the Excel document $data = new Spreadsheet_Excel_Reader(); // Set output Encoding. $data->setOutputEncoding(api_get_system_encoding()); // Reading the xls document. $data->read($_FILES['user_upload_quiz']['tmp_name']); $correctScore = isset($_POST['correct_score']) ? $_POST['correct_score'] : null; $incorrectScore = isset($_POST['incorrect_score']) ? $_POST['incorrect_score'] : null; $useCustomScore = isset($_POST['user_custom_score']) ? true : false; $propagateNegative = 0; if ($useCustomScore && !empty($incorrectScore)) { if ($incorrectScore < 0) { $propagateNegative = 1; } } // Variables $quiz_index = 0; $question_title_index = array(); $question_name_index_init = array(); $question_name_index_end = array(); $score_index = array(); $feedback_true_index = array(); $feedback_false_index = array(); $number_questions = 0; $question_description_index = array(); // Reading all the first column items sequentially to create breakpoints for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) { if ($data->sheets[0]['cells'][$i][1] == 'Quiz' && $i == 1) { $quiz_index = $i; // Quiz title position, only occurs once } elseif ($data->sheets[0]['cells'][$i][1] == 'Question') { $question_title_index[] = $i; // Question title position line $question_name_index_init[] = $i + 1; // Questions name 1st position line $number_questions++; } elseif ($data->sheets[0]['cells'][$i][1] == 'Score') { $question_name_index_end[] = $i - 1; // Question name position $score_index[] = $i; // Question score position } elseif ($data->sheets[0]['cells'][$i][1] == 'FeedbackTrue') { $feedback_true_index[] = $i; // FeedbackTrue position (line) } elseif ($data->sheets[0]['cells'][$i][1] == 'FeedbackFalse') { $feedback_false_index[] = $i; // FeedbackFalse position (line) } elseif ($data->sheets[0]['cells'][$i][1] == 'EnrichQuestion') { $question_description_index[] = $i; } } // Variables $quiz = array(); $question = array(); $new_answer = array(); $score_list = array(); $feedback_true_list = array(); $feedback_false_list = array(); $question_description = array(); // Getting questions. $k = $z = $q = $l = $m = 0; for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) { if (is_array($data->sheets[0]['cells'][$i])) { $column_data = $data->sheets[0]['cells'][$i]; // Fill all column with data to have a full array for ($x = 1; $x <= $data->sheets[0]['numCols']; $x++) { if (empty($column_data[$x])) { $data->sheets[0]['cells'][$i][$x] = ''; } } // Array filled with data $column_data = $data->sheets[0]['cells'][$i]; } else { $column_data = ''; } // Fill quiz data if ($quiz_index == $i) { // The title always in the first position $quiz = $column_data; } elseif (in_array($i, $question_title_index)) { //a complete line where 1st column is 'Question' $question[$k] = $column_data; $k++; } elseif (in_array($i, $score_index)) { //a complete line where 1st column is 'Score' $score_list[$z] = $column_data; $z++; } elseif (in_array($i, $feedback_true_index)) { //a complete line where 1st column is 'FeedbackTrue' $feedback_true_list[$q] = $column_data; $q++; } elseif (in_array($i, $feedback_false_index)) { //a complete line where 1st column is 'FeedbackFalse' for wrong answers $feedback_false_list[$l] = $column_data; $l++; } elseif (in_array($i, $question_description_index)) { //a complete line where 1st column is 'EnrichQuestion' $question_description[$m] = $column_data; $m++; } } // Get answers for ($i = 0; $i < count($question_name_index_init); $i++) { for ($j = $question_name_index_init[$i]; $j <= $question_name_index_end[$i]; $j++) { if (is_array($data->sheets[0]['cells'][$j])) { $column_data = $data->sheets[0]['cells'][$j]; // Fill all column with data for ($x = 1; $x <= $data->sheets[0]['numCols']; $x++) { if (empty($column_data[$x])) { $data->sheets[0]['cells'][$j][$x] = ''; } } $column_data = $data->sheets[0]['cells'][$j]; // Array filled of data if (is_array($data->sheets[0]['cells'][$j]) && count($data->sheets[0]['cells'][$j]) > 0) { $new_answer[$i][$j] = $data->sheets[0]['cells'][$j]; } } } } // Quiz title. $quiz_title = $quiz[2]; if ($quiz_title != '') { // Variables $type = 2; $random = $active = $results = $max_attempt = $expired_time = 0; // Make sure feedback is enabled (3 to disable), otherwise the fields // added to the XLS are not shown, which is confusing $feedback = 0; // Quiz object $exercise = new Exercise(); // $quiz_id = $exercise->createExercise($quiz_title, $expired_time, $type, $random, $active, $results, $max_attempt, $feedback, $propagateNegative); if ($quiz_id) { // insert into the item_property table api_item_property_update($_course, TOOL_QUIZ, $quiz_id, 'QuizAdded', api_get_user_id()); // Import questions. for ($i = 0; $i < $number_questions; $i++) { // Question name $question_title = $question[$i][2]; $question_description_text = "<p></p>"; if (isset($question_description[$i][2])) { // Question description. $question_description_text = "<p>" . $question_description[$i][2] . "</p>"; } // Unique answers are the only question types available for now // through xls-format import $question_id = null; $detectQuestionType = detectQuestionType($new_answer[$i], $score_list); /** @var Question $answer */ switch ($detectQuestionType) { case FREE_ANSWER: $answer = new FreeAnswer(); break; case GLOBAL_MULTIPLE_ANSWER: $answer = new GlobalMultipleAnswer(); break; case MULTIPLE_ANSWER: $answer = new MultipleAnswer(); break; case UNIQUE_ANSWER: default: $answer = new UniqueAnswer(); break; } if ($question_title != '') { $question_id = $answer->create_question($quiz_id, $question_title, $question_description_text, 0, $answer->type); } $total = 0; if (is_array($new_answer[$i]) && !empty($question_id)) { $id = 1; $answers_data = $new_answer[$i]; $globalScore = null; $objAnswer = new Answer($question_id, $courseId); $globalScore = $score_list[$i][3]; // Calculate the number of correct answers to divide the // score between them when importing from CSV $numberRightAnswers = 0; foreach ($answers_data as $answer_data) { if (strtolower($answer_data[3]) == 'x') { $numberRightAnswers++; } } foreach ($answers_data as $answer_data) { $answerValue = $answer_data[2]; $correct = 0; $score = 0; if (strtolower($answer_data[3]) == 'x') { $correct = 1; $score = $score_list[$i][3]; $comment = $feedback_true_list[$i][2]; } else { $comment = $feedback_false_list[$i][2]; $floatVal = (double) $answer_data[3]; if (is_numeric($floatVal)) { $score = $answer_data[3]; } } if ($useCustomScore) { if ($correct) { $score = $correctScore; } else { $score = $incorrectScore; } } // Fixing scores: switch ($detectQuestionType) { case GLOBAL_MULTIPLE_ANSWER: $score /= $numberRightAnswers; break; case UNIQUE_ANSWER: break; case MULTIPLE_ANSWER: if (!$correct) { //$total = $total - $score; } break; } $objAnswer->createAnswer($answerValue, $correct, $comment, $score, $id); $total += $score; $id++; } $objAnswer->save(); $questionObj = Question::read($question_id, $courseId); switch ($detectQuestionType) { case GLOBAL_MULTIPLE_ANSWER: $questionObj->updateWeighting($globalScore); break; case UNIQUE_ANSWER: case MULTIPLE_ANSWER: default: $questionObj->updateWeighting($total); break; } $questionObj->save(); } else { if ($detectQuestionType === FREE_ANSWER) { $questionObj = Question::read($question_id, $courseId); $globalScore = $score_list[$i][3]; $questionObj->updateWeighting($globalScore); $questionObj->save(); } } } } if (isset($_SESSION['lpobject'])) { if ($debug > 0) { error_log('New LP - SESSION[lpobject] is defined', 0); } $oLP = unserialize($_SESSION['lpobject']); if (is_object($oLP)) { if ($debug > 0) { error_log('New LP - oLP is object', 0); } if (empty($oLP->cc) or $oLP->cc != api_get_course_id()) { if ($debug > 0) { error_log('New LP - Course has changed, discard lp object', 0); } $oLP = null; Session::erase('oLP'); Session::erase('lpobject'); } else { $_SESSION['oLP'] = $oLP; } } } if (isset($_SESSION['oLP']) && isset($_GET['lp_id'])) { $previous = $_SESSION['oLP']->select_previous_item_id(); $parent = 0; // Add a Quiz as Lp Item $_SESSION['oLP']->add_item($parent, $previous, TOOL_QUIZ, $quiz_id, $quiz_title, ''); // Redirect to home page for add more content header('location: ../newscorm/lp_controller.php?' . api_get_cidreq() . '&action=add_item&type=step&lp_id=' . Security::remove_XSS($_GET['lp_id'])); exit; } else { // header('location: exercise.php?' . api_get_cidreq()); echo '<script>window.location.href = "' . api_get_path(WEB_CODE_PATH) . 'exercice/admin.php?' . api_get_cidReq() . '&exerciseId=' . $quiz_id . '&session_id=' . api_get_session_id() . '"</script>'; } } }
function read() { $this->load->library("Spreadsheet_Excel_Reader"); $this->rapyd->load("datagrid2", "dataform"); $salida = anchor('inventario/sinvactu', 'Atras'); $type = ''; if (isset($_FILES['archivoUserFile']['type'])) { $type = $_FILES['archivoUserFile']['type']; } if ($type == 'application/x-msexcel') { $name = $_FILES['archivoUserFile']['name']; $dir = ".././" . $name; if (copy($_FILES['archivoUserFile']['tmp_name'], $dir)) { $tmp = $dir; //$_FILES['archivoUserFile']['tmp_name']; $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('CP1251'); $data->read($tmp); error_reporting(E_ALL ^ E_NOTICE); $cols = array(); for ($i = 0; $i <= $data->sheets[0]['numRows']; $i++) { $ref = 0; for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) { $cols[$j - 1] = $data->sheets[0]['cells'][$i][$j]; if (!empty($data->sheets[0]['cells'][$i][$j])) { $ref++; } } if ($ref > 2) { break; } } $c = 0; for ($i = 0; $i <= $data->sheets[0]['numRows']; $i++) { $ref = 0; $j = 1; foreach ($cols as $col) { $data3[$i][$col] = $data->sheets[0]['cells'][$i][$j]; if (!empty($data->sheets[0]['cells'][$i][$j])) { $ref++; } $j++; } if ($ref > 2 && implode(' ', $data3[$i]) != implode(' ', $cols)) { $data4[$c] = $data3[$i]; $c++; } } $form = new DataForm("/inventario/sinvactu/actualiza"); $form->free = new freeField("Campos.Archivo xls", "free", "Campos de El Sistema"); $grid = new DataGrid2("Archivo Cargado", $data4); $j = 0; $campos .= 'cols="+$("#cols").val()+"&&dir="+$("#dir").val()'; foreach ($cols as $col) { $grid->column("{$col}", "<#{$col}#>"); $campo = "campo{$j}"; $form->{$campo} = new dropdownField("{$col}", "campo{$j}"); $form->{$campo}->option("ignorar", "ignorar"); $form->{$campo}->option("codigo", "codigo"); $form->{$campo}->option("costo", "costo"); $form->{$campo}->option("descrip", "descrip"); $form->{$campo}->option("descrip2", "descrip2"); $form->{$campo}->option("clave", "clave"); $form->{$campo}->option("grupo", "grupo"); $form->{$campo}->option("iva", "iva"); for ($i = 1; $i <= 3; $i++) { $form->{$campo}->option("base{$i}", "Base{$i}"); $form->{$campo}->option("margen{$i}", "Margen{$i}"); $form->{$campo}->option("precio{$i}", "Precio{$i}"); } $form->{$campo}->style = 'width:150px;'; $j++; $campos .= "+" . "\"&&" . $campo . "=\"+\$(\"#" . $campo . "\").val()"; } //echo $campos; $form->cols = new inputField("", "cols"); $form->cols->insertValue = implode(',', $cols); $form->cols->type = 'hidden'; $form->dir = new inputField("", "dir"); $form->dir->insertValue = $dir; $form->dir->type = 'hidden'; //$form->submit("btnsubmit","Actualizar"); $link = site_url('inventario/sinvactu/actualiza'); $script = ' function actu(){ a=confirm("¿Esta Seguro que de desea Actualizar el Inventario ?"); if(a){ $.ajax({ type: "POST", processData:false, url: "' . $link . '", data: "' . $campos . ', success: function(msg){ if(msg=="s.i"){ alert("El Inventario fue Actualizado."); } else{ alert(msg); } } }); } } '; $form->script($script); $form->button("actualiza", "Actualizar", "javascript:actu();"); $form->build_form(); $grid->build(); $data2['content'] = $form->output . $salida . $grid->output; } } else { $data2['content'] = $salida; } $data2['title'] = "<h1>Actualización de Inventario</h1>"; $data2["head"] = script("jquery.pack.js") . $this->rapyd->get_head(); $this->load->view('view_ventanas', $data2); }
<?php // Test CVS require_once 'Excel/reader.php'; // ExcelFile($filename, $encoding); $data = new Spreadsheet_Excel_Reader(); // Set output Encoding. $data->setOutputEncoding('CP1251'); /*** * if you want you can change 'iconv' to mb_convert_encoding: * $data->setUTFEncoder('mb'); * **/ /*** * By default rows & cols indeces start with 1 * For change initial index use: * $data->setRowColOffset(0); * **/ /*** * Some function for formatting output. * $data->setDefaultFormat('%.2f'); * setDefaultFormat - set format for columns with unknown formatting * * $data->setColumnFormat(4, '%.3f'); * setColumnFormat - set format for column (apply only to number fields) * **/ $data->read('jxlrwtest.xls'); /*
function doadd($id, $thn = "", $bln = "") { $this->authentication->verify('spkp_absen_tunjangan', 'add'); if (count($_FILES) > 0) { $path = './public/files/spkp_absen_tunjangan'; if (!is_dir($path)) { mkdir($path); } $path .= '/' . $id; if (!is_dir($path)) { mkdir($path); } $path .= '/' . $thn; if (!is_dir($path)) { mkdir($path); } $path .= '/' . $bln; if (!is_dir($path)) { mkdir($path); } @unlink($path . "/" . $_FILES['filename']['name']); $config['upload_path'] = $path; $config['allowed_types'] = '*'; $this->load->library('upload', $config); $this->upload->initialize($config); $upload = $this->upload->do_upload('filename'); $upload_data = $this->upload->data(); if ($upload === FALSE) { echo $this->upload->display_errors() . "<br>"; } else { $OLERead = new OLERead(); $data = new Spreadsheet_Excel_Reader($OLERead); $data->setOutputEncoding('CP1251'); $data->read($path . "/" . $upload_data['file_name']); $item = array(); for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) { if ($i == 1) { for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) { $col[$j] = str_replace(" ", "_", str_replace("sakit/cuti/ijin", "sic", strtolower($data->sheets[0]['cells'][$i][$j]))); } } else { $vals = array(); for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) { if ($col[$j] == "status") { $vals[$col[$j]] = $data->sheets[0]['cells'][$i][$j] == "open" ? 0 : 1; } else { $vals[$col[$j]] = isset($data->sheets[0]['cells'][$i][$j]) ? $data->sheets[0]['cells'][$i][$j] : "-"; } } $item[] = $vals; } } echo "OK_" . $this->spkp_absen_tunjangan_model->doimport_tukin($id, $thn, $bln, $item); } } else { echo "ERROR_Upload failed"; } }
function getSonucExcel($post, $get, $files) { $_db = JFactory::getOracleDBO(); $user =& JFactory::getUser(); $user_id = $user->getOracleUserId(); /////// EKLENEN FILENAME BIZDE KAYITLIMI DEGILMI ////////////////////7 // $filename = $files['upload']['name']; // // $paktetBul = explode('_', $filename); // $paket_Id = explode('.',$paktetBul[2]); $paket_Id = $post['paketId']; // if(!file_exists(EK_FOLDER.'sinav_bildirimleri/'.$filename) || $paktetBul[0] != $user_id || $paktetBul[1] != $get['sinav']){ // $return['hataMesaji'][1] = 'Sonuç bildirimi gönderdiğiniz dosya sistemimizde yer almamaktadır. Lütfen sistemden indirdiğiniz dosyanın adını değiştirmeden yollayınız.'; // return $return; // } ////////////////////////////////////////////////////////////////////777 if ($files['upload']['size'] > 0) { if ($files['upload']['type'] == 'application/vnd.ms-excel') { // $objPHPExcel = PHPExcel_IOFactory::load($files['upload']['tmp_name']); $uzanti = "xls"; $excel = new Spreadsheet_Excel_Reader(); $excel->setOutputEncoding('windows-1254'); $excel->read($files['upload']['tmp_name']); foreach ($excel->sheets[0]['cells'][1] as $key => $val) { $cols[$key] = $val; } $keySql = array('1' => 'TC_KIMLIK', 'UYRUK', 'ADI', 'SOYADI', 'DOGUM_TARIHI', 'CINSIYETI', 'EGITIMI', 'CALISMA_DURUMU', 'EMAIL', 'TELEFON', 'IBAN', 'YETERLILIK_KODU', 'BIRIM_KODU', 'SINAV_TURU_KODU', 'SINAV_TARIHI', 'SINAV_SAATI', 'SINAV_YERI_ID', 'DEGERLENDIRICI_TC_KIMLIK', 'PUAN', 'BASARI_DURUMU'); $bossatir = 0; $x = 4; for ($i = 4; $i <= count($excel->sheets[0]['cells']); $i++) { for ($y = 1; $y <= 20; $y++) { if (!isset($excel->sheets[0]['cells'][$i][$y])) { $excel->sheets[0]['cells'][$i][$y] = ""; } } foreach ($excel->sheets[0]['cells'][$i] as $key => $val) { $data[$x][$keySql[$key]] = mb_convert_encoding($val, "UTF-8", "windows-1254"); if ($cols[$key] == "dogumtarihi" && $data[$x][$keySql[$key]] != "") { $timestamp = trim($data[$x][$keySql[$key]]); $mysqlDate = date('d/m/Y', strtotime('1899-12-31+' . ($timestamp - 1) . ' days')); if (strpos($timestamp, ".") || strpos($timestamp, "/")) { $data[$x][$keySql[$key]] = str_replace('.', '/', $timestamp); } else { $data[$x][$keySql[$key]] = $mysqlDate; } } else { if ($cols[$key] == "sinavtarihi" && $data[$x][$keySql[$key]] != "") { $timestamp = trim($data[$x][$keySql[$key]]); $mysqlDate = date('d/m/Y', strtotime('1899-12-31+' . ($timestamp - 1) . ' days')); if (strpos($timestamp, ".") || strpos($timestamp, "/")) { $data[$x][$keySql[$key]] = str_replace('.', '/', $timestamp); } else { $data[$x][$keySql[$key]] = $mysqlDate; } } else { if ($cols[$key] == "tckn" && $data[$x][$keySql[$key]] == '') { $bossatir++; break; } else { if ($data[$x][$keySql[$key]] != '') { $data[$x][$keySql[$key]] = trim($data[$x][$keySql[$key]]); } } } } } $x++; if ($bossatir > 0) { break; } } } else { if ($files['upload']['type'] == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || $files['upload']['type'] == "application/octet-stream") { $objReader = PHPExcel_IOFactory::createReader('Excel2007'); $objReader->setReadDataOnly(true); $objPHPExcel = $objReader->load($files['upload']['tmp_name']); $uzanti = "xlsx"; $objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); $highestColumn = $objWorksheet->getHighestColumn(); $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); $data = array(); for ($col = 0; $col <= $highestColumnIndex - 1; ++$col) { $key[] = $objWorksheet->getCellByColumnAndRow($col, 1)->getValue(); } $keySql = array('0' => 'TC_KIMLIK', 'UYRUK', 'ADI', 'SOYADI', 'DOGUM_TARIHI', 'CINSIYETI', 'EGITIMI', 'CALISMA_DURUMU', 'YETERLILIK_KODU', 'BIRIM_KODU', 'SINAV_TURU_KODU', 'SINAV_TARIHI', 'SINAV_SAATI', 'SINAV_YERI_ID', 'DEGERLENDIRICI_TC_KIMLIK', 'PUAN', 'BASARI_DURUMU'); $bossatir = 0; for ($row = 4; $row <= $highestRow; ++$row) { for ($col = 0; $col <= $highestColumnIndex - 1; ++$col) { if ($key[$col] == "dogumtarihi") { if ($objWorksheet->getCellByColumnAndRow($col, $row)->getValue() != '') { $timestamp = trim($objWorksheet->getCellByColumnAndRow($col, $row)->getValue()); $mysqlDate = date('d/m/Y', strtotime('1899-12-31+' . ($timestamp - 1) . ' days')); if (strpos($timestamp, ".") || strpos($timestamp, "/")) { $data[$row][$keySql[$col]] = str_replace('.', '/', $timestamp); } else { $data[$row][$keySql[$col]] = $mysqlDate; } } } else { if ($key[$col] == "sinavtarihi") { if ($objWorksheet->getCellByColumnAndRow($col, $row)->getValue() != '') { $timestamp = trim($objWorksheet->getCellByColumnAndRow($col, $row)->getValue()); $mysqlDate = date('d/m/Y', strtotime('1899-12-31+' . ($timestamp - 1) . ' days')); if (strpos($timestamp, ".") || strpos($timestamp, "/")) { $data[$row][$keySql[$col]] = str_replace('.', '/', $timestamp); } else { $data[$row][$keySql[$col]] = $mysqlDate; } } } else { if ($key[$col] == "sinavsaati") { if ($objWorksheet->getCellByColumnAndRow($col, $row)->getValue() != '') { $mysqlDate = PHPExcel_Style_NumberFormat::toFormattedString(trim($objWorksheet->getCellByColumnAndRow($col, $row)->getCalculatedValue()), 'hh:mm'); $data[$row][$keySql[$col]] = $mysqlDate; } } else { if ($key[$col] == "tckn" && $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() == '') { $bossatir++; break; } else { if ($objWorksheet->getCellByColumnAndRow($col, $row)->getValue() != '') { $data[$row][$keySql[$col]] = trim($objWorksheet->getCellByColumnAndRow($col, $row)->getValue()); } } } } } } if ($bossatir > 0) { break; } } } else { print 'dosya formatı yanlış'; exit; } } $sql = "select yeterlilik_id from m_belgelendirme_sinav where sinav_id=" . $get["sinav"]; $yeterlilik_id = $_db->prep_exec($sql, array()); $yeterlilik_id = $yeterlilik_id[0]["YETERLILIK_ID"]; $sinavYerleri = $this->sinavYeriKontrol($user_id, $yeterlilik_id); $degerlendiriciler = $this->sinavDegerlendiriciKontrol($user_id, $yeterlilik_id); $keyArray = array(); $dataTest = array(); $dataTest = $data; $tcArray = array(); foreach ($dataTest as $key => $cow) { $keyArray[] = $key; unset($dataTest[$key]['PUAN']); unset($dataTest[$key]['BASARI_DURUMU']); unset($dataTest[$key]['SINAV_TARIHI']); unset($dataTest[$key]['SINAV_SAATI']); unset($dataTest[$key]['YETERLILIK_KODU']); unset($dataTest[$key]['UYRUK']); unset($dataTest[$key]['DEGERLENDIRICI_TC_KIMLIK']); settype($dataTest[$key]['TC_KIMLIK'], "string"); $dataTest[$key]['SINAV_YERI_ID'] = (int) $dataTest[$key]['SINAV_YERI_ID']; $dataTest[$key]['BIRIM_KODU'] = ucwords(trim(str_replace(' ', '', $dataTest[$key]['BIRIM_KODU']))); $dataTest[$key]['SINAV_TURU_KODU'] = ucwords(trim(str_replace(' ', '', $dataTest[$key]['SINAV_TURU_KODU']))); if (isset($dataTest[$key]['IBAN'])) { //ALT+255 BOŞLUĞU YAKALAR $dataTest[$key]['IBAN'] = str_replace(array(' ', chr(0xc2) . chr(0xa0)), array('', ''), $dataTest[$key]['IBAN']); } if (isset($dataTest[$key]['TELEFON'])) { $dataTest[$key]['TELEFON'] = str_replace(array(' ', '(', ')', '-', '+90'), array('', '', '', '', ''), $dataTest[$key]['TELEFON']); if (substr($dataTest[$key]['TELEFON'], 0, 1) == "0") { $dataTest[$key]['TELEFON'] = substr($dataTest[$key]['TELEFON'], 1); } } if (!in_array($dataTest[$key]['TC_KIMLIK'], $tcArray)) { $tcArray[] = $dataTest[$key]['TC_KIMLIK']; $dataTest[$key]['ADI'] = FormFactory::ucWordsTR($dataTest[$key]['ADI']); $dataTest[$key]['SOYADI'] = FormFactory::toUpperCase($dataTest[$key]['SOYADI']); $cinsiyet = FormFactory::toUpperCase($dataTest[$key]['CINSIYETI']); if ($cinsiyet == 'ERKEK') { $dataTest[$key]['CINSIYETI'] = 1; $data[$key]['CINSIYETI'] = 1; } else { if ($cinsiyet == 'KADIN') { $dataTest[$key]['CINSIYETI'] = 2; $data[$key]['CINSIYETI'] = 2; } else { if ($cinsiyet == 'BELİRTİLMEMİŞ') { $dataTest[$key]['CINSIYETI'] = 3; $data[$key]['CINSIYETI'] = 3; } } } $egitimm = FormFactory::toUpperCase(trim(str_replace(' ', '', $dataTest[$key]['EGITIMI']))); if ($egitimm == 'OKURYAZARDEĞİL') { $dataTest[$key]['EGITIMI'] = 1; $data[$key]['EGITIMI'] = 1; } else { if ($egitimm == 'OKURYAZAR') { $dataTest[$key]['EGITIMI'] = 2; $data[$key]['EGITIMI'] = 2; } else { if ($egitimm == 'İLKOKUL') { $dataTest[$key]['EGITIMI'] = 3; $data[$key]['EGITIMI'] = 3; } else { if ($egitimm == 'ORTAOKUL') { $dataTest[$key]['EGITIMI'] = 4; $data[$key]['EGITIMI'] = 4; } else { if ($egitimm == 'MESLEKLİSESİ') { $dataTest[$key]['EGITIMI'] = 5; $data[$key]['EGITIMI'] = 5; } else { if ($egitimm == 'GENELLİSE') { $dataTest[$key]['EGITIMI'] = 6; $data[$key]['EGITIMI'] = 6; } else { if ($egitimm == 'MESLEKYÜKSEKOKULU') { $dataTest[$key]['EGITIMI'] = 7; $data[$key]['EGITIMI'] = 7; } else { if ($egitimm == 'LİSANS') { $dataTest[$key]['EGITIMI'] = 8; $data[$key]['EGITIMI'] = 8; } else { if ($egitimm == 'YÜKSEKLİSANS') { $dataTest[$key]['EGITIMI'] = 9; $data[$key]['EGITIMI'] = 9; } else { if ($egitimm == 'DOKTORA') { $dataTest[$key]['EGITIMI'] = 10; $data[$key]['EGITIMI'] = 10; } } } } } } } } } } $calismaDurum = FormFactory::toUpperCase(trim(str_replace(' ', '', $dataTest[$key]['CALISMA_DURUMU']))); if ($calismaDurum == 'ÇALIŞIYOR') { $dataTest[$key]['CALISMA_DURUMU'] = 1; $data[$key]['CALISMA_DURUMU'] = 1; } else { if ($calismaDurum == 'ÇALIŞMIYOR') { $dataTest[$key]['CALISMA_DURUMU'] = 2; $data[$key]['CALISMA_DURUMU'] = 2; } else { if ($calismaDurum == 'STAJYAPIYOR') { $dataTest[$key]['CALISMA_DURUMU'] = 3; $data[$key]['CALISMA_DURUMU'] = 3; } } } } else { unset($dataTest[$key]['ADI']); unset($dataTest[$key]['SOYADI']); unset($dataTest[$key]['DOGUM_TARIHI']); unset($dataTest[$key]['CINSIYETI']); unset($dataTest[$key]['EGITIMI']); unset($dataTest[$key]['CALISMA_DURUMU']); } } //array_splice($data[4], 5) ilk 5 degerden sonrasını siliyor. 5'degerden sonrasını sana döndürüyor. $sql = "select * from m_yeterlilik where yeterlilik_id=" . $yeterlilik_id; $yeterlilik = $_db->prep_exec($sql, array()); $yeni_mi = $yeterlilik[0]["YENI_MI"]; //Eski excel ve yeni excel format uyuşmazlıkları için eklendi $sinavTarihi = $this->getSinavTarihi($get['sinav']); $sql_add = ""; if (strtotime(str_replace('/', '-', $sinavTarihi)) > strtotime(str_replace('/', '-', '20-07-2015'))) { $sql_add = ",M_BELGELENDIRME_OGRENCI.TELEFON,M_BELGELENDIRME_OGRENCI.EMAIL,M_BELGELENDIRME_OGRENCI.IBAN"; } if ($yeni_mi == 1) { $sql = "SELECT DISTINCT M_BELGELENDIRME_OGRENCI.TC_KIMLIK, M_BELGELENDIRME_OGRENCI.ADI, M_BELGELENDIRME_OGRENCI.SOYADI, M_BELGELENDIRME_OGRENCI.DOGUM_TARIHI, \n M_BELGELENDIRME_OGRENCI.CINSIYETI, M_BELGELENDIRME_OGRENCI.EGITIMI,\n M_BELGELENDIRME_OGRENCI.CALISMA_DURUMU,\n \t\t\t\t\t\tM_BIRIM.BIRIM_KODU, M_BELGELENDIRME_ADAY_BILDIRIM.SINAV_TURU_KODU,\n M_BELGELENDIRME_ADAY_BILDIRIM.BILDIRIM_ID,M_BELGELENDIRME_ADAY_BILDIRIM.BIRIM_ID,M_BELGELENDIRME_ADAY_BILDIRIM.SINAV_TURU_KODU,\n M_BELGELENDIRME_ADAY_BILDIRIM.SINAV_YERI_ID, M_BELGELENDIRME_ADAY_BILDIRIM.DEGERLENDIRICI_TC_KIMLIK" . $sql_add . "\n FROM M_BELGELENDIRME_OGRENCI\n JOIN M_BELGELENDIRME_ADAY_BILDIRIM ON M_BELGELENDIRME_OGRENCI.TC_KIMLIK = M_BELGELENDIRME_ADAY_BILDIRIM.TC_KIMLIK\n JOIN M_BIRIM ON M_BELGELENDIRME_ADAY_BILDIRIM.BIRIM_ID = M_BIRIM.BIRIM_ID\n WHERE M_BELGELENDIRME_ADAY_BILDIRIM.SINAV_ID = ? AND PAKET_ID=?\n ORDER BY M_BELGELENDIRME_ADAY_BILDIRIM.BILDIRIM_ID"; } else { $sql = "SELECT DISTINCT M_BELGELENDIRME_OGRENCI.TC_KIMLIK, M_BELGELENDIRME_OGRENCI.ADI, M_BELGELENDIRME_OGRENCI.SOYADI, M_BELGELENDIRME_OGRENCI.DOGUM_TARIHI, \n M_BELGELENDIRME_OGRENCI.CINSIYETI, M_BELGELENDIRME_OGRENCI.EGITIMI,\n M_BELGELENDIRME_OGRENCI.CALISMA_DURUMU,\n \t\t\t\t\t\tM_YETERLILIK_ALT_BIRIM.YETERLILIK_ALT_BIRIM_NO AS BIRIM_KODU, M_BELGELENDIRME_ADAY_BILDIRIM.SINAV_TURU_KODU,\n M_BELGELENDIRME_ADAY_BILDIRIM.BILDIRIM_ID,M_BELGELENDIRME_ADAY_BILDIRIM.BIRIM_ID,M_BELGELENDIRME_ADAY_BILDIRIM.SINAV_TURU_KODU,\n M_BELGELENDIRME_ADAY_BILDIRIM.SINAV_YERI_ID, M_BELGELENDIRME_ADAY_BILDIRIM.DEGERLENDIRICI_TC_KIMLIK" . $sql_add . "\n FROM M_BELGELENDIRME_OGRENCI\n JOIN M_BELGELENDIRME_ADAY_BILDIRIM ON M_BELGELENDIRME_OGRENCI.TC_KIMLIK = M_BELGELENDIRME_ADAY_BILDIRIM.TC_KIMLIK\n JOIN M_YETERLILIK_ALT_BIRIM ON M_BELGELENDIRME_ADAY_BILDIRIM.BIRIM_ID = M_YETERLILIK_ALT_BIRIM.YETERLILIK_ALT_BIRIM_ID\n WHERE M_BELGELENDIRME_ADAY_BILDIRIM.SINAV_ID = ? AND PAKET_ID=?\n ORDER BY M_BELGELENDIRME_ADAY_BILDIRIM.BILDIRIM_ID"; } $kayitliaday = $_db->prep_exec($sql, array($get['sinav'], $paket_Id)); $adayBirims = array(); $adaylar = array(); $tcArray = array(); foreach ($kayitliaday as $key => $row) { $adayBirims[$keyArray[$key]][] = $kayitliaday[$key]['BIRIM_ID']; $adayBirims[$keyArray[$key]][] = $kayitliaday[$key]['SINAV_TURU_KODU']; unset($kayitliaday[$key]['BIRIM_ID']); unset($kayitliaday[$key]['BILDIRIM_ID']); unset($kayitliaday[$key]['DEGERLENDIRICI_TC_KIMLIK']); if ($yeni_mi == 1) { $kayitliaday[$key]['BIRIM_KODU'] = trim($kayitliaday[$key]['BIRIM_KODU']); } else { $kayitliaday[$key]['BIRIM_KODU'] = trim($yeterlilik[0]['YETERLILIK_KODU']) . '/' . trim($kayitliaday[$key]['BIRIM_KODU']); } $kayitliaday[$key]['BIRIM_KODU'] = str_replace(" ", "", $kayitliaday[$key]['BIRIM_KODU']); $kayitliaday[$key]['SINAV_YERI_ID'] = (int) $kayitliaday[$key]['SINAV_YERI_ID']; if (!in_array($kayitliaday[$key]['TC_KIMLIK'], $tcArray)) { $tcArray[] = $kayitliaday[$key]['TC_KIMLIK']; $kayitliaday[$key]['CINSIYETI'] = (int) $kayitliaday[$key]['CINSIYETI']; $kayitliaday[$key]['EGITIMI'] = (int) $kayitliaday[$key]['EGITIMI']; $kayitliaday[$key]['CALISMA_DURUMU'] = (int) $kayitliaday[$key]['CALISMA_DURUMU']; } else { unset($kayitliaday[$key]['ADI']); unset($kayitliaday[$key]['SOYADI']); unset($kayitliaday[$key]['DOGUM_TARIHI']); unset($kayitliaday[$key]['CINSIYETI']); unset($kayitliaday[$key]['EGITIMI']); unset($kayitliaday[$key]['CALISMA_DURUMU']); } $adaylar[$keyArray[$key]] = $kayitliaday[$key]; } $hataArray = array(); for ($i = 4; $i < count($dataTest) + 4; $i++) { if ($adaylar[$i] != $dataTest[$i]) { $hatalikolonlar = ""; for ($j = 0; $j < count($keySql); $j++) { if ($adaylar[$i][$keySql[$j]] != $dataTest[$i][$keySql[$j]]) { if ($keySql[$j] == "EMAIL" and $dataTest[$i][$keySql[$j]] == "" or $keySql[$j] == "TELEFON" and $dataTest[$i][$keySql[$j]] == "" or $keySql[$j] == "IBAN" and $dataTest[$i][$keySql[$j]] == "") { } else { $hatalikolonlar .= $keySql[$j] . " "; } } } if ($hatalikolonlar != "") { $return["adayBilgisi"][] = $i . " (" . $hatalikolonlar . ") "; } } } if (count($return["adayBilgisi"]) == 0) { $sinavTarihi = $this->getSinavTarihi($get['sinav']); $sinavYerleri = $this->sinavYeriKontrol($user_id, $yeterlilik_id); $degerlendiriciler = $this->sinavDegerlendiriciKontrol($user_id, $yeterlilik_id); foreach ($data as $key => $satir) { ////////////// EXCEL'DEN GELEN SINAV TARİHİ KONTROLÜ /////////////// if (strtotime($sinavTarihi) > strtotime(ereg_replace("/", "-", $satir["SINAV_TARIHI"]))) { $return["hataMesaji"][4] = "Aşağıdaki satırlarda verilen Sınav Tarihleri, Sınav Programınızda belirttiğiniz Başlangıç Tarihinden (" . $sinavTarihi . ") öncedir. Düzeltip dosyanızı yeniden yükleyiniz."; $return["sinavTarihi"][] = array($key, $satir["SINAV_TARIHI"]); } ////////////// EXCEL'DEN GELEN SINAV TARİHİ 360 GÜN KONTROLÜ /////////////// if (strtotime('+360 days', strtotime($sinavTarihi)) < strtotime(ereg_replace("/", "-", $satir["SINAV_TARIHI"]))) { $return["hataMesaji"][2] = "Aşağıdaki satırlarda verilen Sınav Tarihleri, Sınav Programınızda belirttiğiniz Başlangıç Tarihinden (" . $sinavTarihi . ") 1 yıl içinde olmalıdır. Düzeltip dosyanızı yeniden yükleyiniz."; $return["sinavTarihi360"][] = array($key, $satir["SINAV_TARIHI"]); } ////////////// EXCEL'DEN GELEN SINAV YERİ KONTROLÜ /////////////// // if (!in_array($satir["SINAV_YERI_ID"], $sinavYerleri)){ // $return["hataMesaji"][5]="Aşağıdaki satırlarda Verdiğiniz Sınav Yeri ID'leri, <a href='index.php?option=com_belgelendirme&view=belgelendirme_islemleri&layout=belgelendirme_sinav_yeri' style='color:red;'>Sınav Yerleriniz</a> arasında yoktur. Düzeltip dosyanızı yeniden yükleyiniz."; // $return["sinavYeri"][]=array($key,$satir["SINAV_YERI_ID"]); // } ////////////// EXCEL'DEN GELEN DEĞERLENDİRİCİLERİN KONTROLÜ /////////////// $degTcKimliks = explode(",", $satir["DEGERLENDIRICI_TC_KIMLIK"]); foreach ($degTcKimliks as $degTcKimlik) { if (!in_array(trim($degTcKimlik), $degerlendiriciler)) { $return["hataMesaji"][6] = "Aşağıdaki satırlarda verdiğiniz Değerlendirici/Gözetmen'ler, <a href='index.php?option=com_belgelendirme&view=belgelendirme_islemleri&layout=belgelendirme_degerlendirici' style='color:red;'>Değerlendiriciler</a> arasında yoktur. Düzeltip dosyanızı yeniden yükleyiniz."; $return["degerlendirici"][] = array($key, $degTcKimlik); } } ////////////// EXCEL'DEN GELEN BASARI VE SONUC KONTROLÜ /////////////// if ($satir["BASARI_DURUMU"] == '' || empty($satir["BASARI_DURUMU"]) || !isset($satir["BASARI_DURUMU"])) { $return["hataMesaji"][7] = "Aşağıdaki satırlarda Sonuç bildirilmemiştir. Düzeltip dosyanızı yeniden yükleyiniz."; $return["sonuc"][] = $key; } else { $sonuc = 0; if (FormFactory::toUpperCase($satir["BASARI_DURUMU"]) == 'BAŞARILI') { if ($satir['PUAN'] == '' || empty($satir["PUAN"]) || !isset($satir["PUAN"])) { $return["hataMesaji"][8] = "Aşağıdaki satırlarda Sonuç bildirilmesine rağmen Puan bildirilmemiştir. Düzeltip dosyanızı yeniden yükleyiniz."; $return["puan"][] = $key; } else { $adaySonuc[$key] = 1; } } else { if (FormFactory::toUpperCase($satir["BASARI_DURUMU"]) == 'BAŞARISIZ') { if ($satir['PUAN'] == '' || empty($satir["PUAN"]) || !isset($satir["PUAN"])) { $satir['PUAN'] = 0; $adaySonuc[$key] = 2; } else { $adaySonuc[$key] = 2; } } else { if (FormFactory::toUpperCase($satir["BASARI_DURUMU"]) == 'GİRMEDİ') { $adaySonuc[$key] = 3; } } } } ///////////// EXCEL'DEN GELEN VERIYI KAYDETME //////////////// $sql = "UPDATE M_BELGELENDIRME_ADAY_BILDIRIM SET PUAN=?, BASARI_DURUMU = ?, DEGERLENDIRICI_TC_KIMLIK = ? WHERE TC_KIMLIK = ? AND SINAV_ID=? AND BIRIM_ID=? AND SINAV_TURU_KODU=? AND PAKET_ID=?"; $param = array($satir['PUAN'], $adaySonuc[$key], $satir['DEGERLENDIRICI_TC_KIMLIK'], $satir['TC_KIMLIK'], $get['sinav'], $adayBirims[$key][0], $adayBirims[$key][1], $paket_Id); $durum = $_db->prep_exec_insert($sql, $param); } if (count($return) == 0) { $sql = "DELETE FROM M_BELGELENDIRME_SINAV_DOSYA WHERE SINAV_ID=? AND PAKET_ID=?"; $_db->prep_exec_insert($sql, array($get['sinav'], $paket_Id)); $paket_id_yeni = $_db->getNextVal('SEQ_SINAV_DOSYA'); $sql = "INSERT INTO M_BELGELENDIRME_SINAV_DOSYA (PAKET_ID,SINAV_ID,TIP,UZANTI) VALUES(?,?,2,?)"; $_db->prep_exec_insert($sql, array($paket_id_yeni, $get['sinav'], $uzanti)); $sql = "UPDATE M_BELGELENDIRME_ADAY_BILDIRIM SET PAKET_ID = ? WHERE SINAV_ID=? AND PAKET_ID=?"; $_db->prep_exec_insert($sql, array($paket_id_yeni, $get['sinav'], $paket_Id)); move_uploaded_file($files['upload']['tmp_name'], EK_FOLDER . "sinav_bildirimleri/" . $user_id . "_" . $get["sinav"] . "_" . $paket_id_yeni . "." . $uzanti); } else { $sql = "UPDATE M_BELGELENDIRME_ADAY_BILDIRIM SET PUAN = null, BASARI_DURUMU = null WHERE PAKET_ID = ?"; $_db->prep_exec_insert($sql, array($paket_Id)); return $return; } } else { $return["hataMesaji"][3] = "Yolladığınız dosyadaki veriler ile indirdiğiniz dosyadaki veriler uyuşmamaktadır. Kontrol ederek tekrar yükleyiniz."; return $return; } } }