<?php error_reporting(0); include '../include/koneksi.php'; ?> <?php if (isset($_FILES['userfile'])) { require_once "library/xlsx_reader/simplexlsx.class.php"; $xlsx = new SimpleXLSX($_FILES['userfile']['tmp_name']); //initial //---------------------------------------- $jumlahrowimport = 0; $gagal = 0; list($cols, ) = $xlsx->dimension(); foreach ($xlsx->rows() as $b => $r) { if ($b <= 1) { continue; } // skip row by row array; //membaca column 1 NIM di excel $nim = $r[1]; //column Nama 2 $nama_mhs = $r[2]; //column number 3 hp di excel $jurusan = $r[3]; $username = $nim; $data = md5($nim); $password = $data; $foto = 'avatar.png'; $tanggal = gmdate("Y-m-d H:i:s", time() + 60 * 60 * 7);
function student_bulk_add($param1 = '') { if ($this->session->userdata('admin_login') != 1) { redirect(base_url(), 'refresh'); } if ($param1 == 'import_excel') { move_uploaded_file($_FILES['userfile']['tmp_name'], 'uploads/student_import.xlsx'); // Importing excel sheet for bulk student uploads include 'simplexlsx.class.php'; $xlsx = new SimpleXLSX('uploads/student_import.xlsx'); list($num_cols, $num_rows) = $xlsx->dimension(); $f = 0; foreach ($xlsx->rows() as $r) { // Ignore the inital name row of excel file if ($f == 0) { $f++; continue; } for ($i = 0; $i < $num_cols; $i++) { if ($i == 0) { $data['name'] = $r[$i]; } else { if ($i == 1) { $data['birthday'] = $r[$i]; } else { if ($i == 2) { $data['sex'] = $r[$i]; } else { if ($i == 3) { $data['address'] = $r[$i]; } else { if ($i == 4) { $data['phone'] = $r[$i]; } else { if ($i == 5) { $data['email'] = $r[$i]; } else { if ($i == 6) { $data['password'] = $r[$i]; } else { if ($i == 7) { $data['roll'] = $r[$i]; } } } } } } } } } $data['class_id'] = $this->input->post('class_id'); $this->db->insert('student', $data); //print_r($data); } redirect(base_url() . 'index.php?admin/student_information/' . $this->input->post('class_id'), 'refresh'); } $page_data['page_name'] = 'student_bulk_add'; $page_data['page_title'] = get_phrase('add_bulk_student'); $this->load->view('backend/index', $page_data); }
/** * Read ExcelX file * * @param string $file_name * @return array */ public static function readXlsxFile($file_name) { $xlsx = new SimpleXLSX(self::TEMP_FOLDER . $file_name); return $xlsx->dimension(); }
<?php include 'simplexlsx.class.php'; $xlsx = new SimpleXLSX('countries_and_population.xlsx'); echo '<table cellpadding="10"> <tr><td valign="top">'; // output worsheet 1 list($num_cols, $num_rows) = $xlsx->dimension(); echo '<h1>Sheet 1</h1>'; echo '<table>'; foreach ($xlsx->rows() as $r) { echo '<tr>'; for ($i = 0; $i < $num_cols; $i++) { echo '<td>' . (!empty($r[$i]) ? $r[$i] : ' ') . '</td>'; } echo '</tr>'; } echo '</table>'; echo '</td><td valign="top">'; // output worsheet 2 list($num_cols, $num_rows) = $xlsx->dimension(2); echo '<h1>Sheet 2</h1>'; echo '<table>'; foreach ($xlsx->rows(2) as $r) { echo '<tr>'; for ($i = 0; $i < $num_cols; $i++) { echo '<td>' . (!empty($r[$i]) ? $r[$i] : ' ') . '</td>'; } echo '</tr>'; } echo '</table>';