how to update xlsx file data into DB using PHPExcel |
I want to update xlsx cell data file into DB using PHPExcel .My cell value starting from Row 12. My Excel sheet printscreen attached.
My controller file like $markid = $this->input->post('markid'); echo $markid; $asses = $this->input->post('sel_ass1'); echo $asses; $csvMimes = array('application/vnd.ms-excel','text/plain','text/csv','text/tsv'); if(!empty($_FILES['file']['name']) && in_array($_FILES['file']['type'],$csvMimes)) { if(is_uploaded_file($_FILES['file']['tmp_name'])) { //open uploaded csv file with read only mode $csvFile = fopen($_FILES['file']['tmp_name'], 'r'); // skip first line // if your csv file have no heading, just comment the next line fgetcsv($csvFile); //parse data from csv file line by line while(($line = fgetcsv($csvFile)) !== FALSE) { //check whether member already exists in database with same email $result = $this->db->get_where("pre_marks", array('regno'=>$line[0],"markid"=>$line[1]))->result(); //echo $result; if(count($result) > 0) { $this->db->update("pre_marks", array("ass1"=>$line[2],"ass2"=>$line[2],"ass3"=>$line[2]),array("regno"=>$line[0])); } fclose($csvFile); $this->session->set_flashdata('success', 'updated successfully'); redirect(site_url('assessment')); I want to update each value into the corresponding regno key. kindly help me to solve my problem . my exported file type is xlsx (2007).
(1) "not working" is not a helpful problem description. At a minimum, indicate what you expect to be happening, and what the problem or error message is.
(2) Use code tags to make long code fragments easier to read ... https://forum.codeigniter.com/misc.php?a...help&hid=7
Hi
Here is my piece of code for uploading data into a table from xlsx file. Few simple things for this: - i use the 1st line to store the column names - for my uploads the 1st column must always be populated I have set up namespaces for my CI3 so i can use "use" tags before the class declaration in my controller/model PHP Code: use PhpOffice\PhpSpreadsheet\IOFactory; PHP Code: $file = '/path/to/your/file.xlsx'; |
Welcome Guest, Not a member yet? Register Sign In |