Hallo! Selamat Datang di Marketplace produk digital, Freelancer terbaik di indonesia (67480 Members, 783 Products, 5290 Topic, 12955 Comments)

Cara Mengatasi Error di sebuah Aplikasi pada Library PHPExcell

Dibuat
Login Terakhir 4 Hari lalu,
Telah Dilihat 1817 Kali
Rivani Noer Maulidi Mengatakan : Sultan Account
  1. Assalamualaikum Warahmatullahi Wabarakatuh...
  2. Mau tanya mengatasi error ini min
Ada 1 File Kiriman :
1. a1.jpg (79 KB)

Ada 4 Jawaban

Bukhori Muslim
commented on 08 Feb 2019 07:25:58
  1. Assalam,.. artinya pada file excel tidak boleh ada yang kosong kolomnya,
  2. ini mau import data ya gan?
  3.  
  4. controller import bikin begini saja :
  5. public function import_excel(){
  6. $config['upload_path'] = 'asset/'.$this->uri->segment(3);
  7. $config['allowed_types'] = 'xlsx|xls';
  8. $this->load->library('upload', $config);
  9. if ( ! $this->upload->do_upload('fileexcel')){
  10. $error = array('error' => $this->upload->display_errors());
  11. }else{
  12. $data = array('upload_data' => $this->upload->data());
  13. $upload_data = $this->upload->data(); //Mengambil detail data yang di upload
  14. $filename = $upload_data['file_name'];//Nama File
  15. $this->model_app->import_excel($this->uri->segment(3),$filename);
  16. redirect('controller_nganu');
  17. }
  18. }
  19.  
  20. Modelsnya begini :
  21. public function import_excel_borongan($directory,$filename){
  22. ini_set('memory_limit', '-1');
  23. $inputFileName = './asset/'.$directory.'/'.$filename;
  24. try {
  25. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  26. } catch(Exception $e) {
  27. die('Error loading file :' . $e->getMessage());
  28. }
  29.  
  30. $worksheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
  31. $numRows = count($worksheet);
  32. for ($i=2; $i < ($numRows+1) ; $i++) {
  33. $a = $worksheet[$i]['A'];
  34. $b = $worksheet[$i]['B'];
  35. $c = $worksheet[$i]['C'];
  36. $d = $worksheet[$i]['D'];
  37.  
  38. $data = array('field1'=>$a,
  39. 'field1'=>$b,
  40. 'field1'=>$c,
  41. 'field1'=>$d);
  42. $this->model_app->insert('rb_table',$data);
  43. }
  44. }
Rivani Noer Maulidi
commented on 09 Feb 2019 07:27:48
  1. Assalam,..
  2. itu mau export gan
  3.  
Rivani Noer Maulidi
commented on 16 Feb 2019 18:05:42
  1. Assalam,..
  2. gimna ya gan caranya
  3.  
Bukhori Muslim
commented on 18 Feb 2019 07:44:24
  1. Assalam,.. coba sesuaikan dengan ini gan file exportnya :
  2. <?php
  3. //load our new PHPExcel library
  4. $this->load->library('excel');
  5. //activate worksheet number 1
  6. $this->excel->setActiveSheetIndex(0);
  7. //name the worksheet
  8. $this->excel->getActiveSheet()->setTitle('Users list');
  9.  
  10. // load database
  11. $this->load->database();
  12.  
  13. // load model
  14. $this->load->model('userModel');
  15.  
  16. // get all users in array formate
  17. $users = $this->userModel->get_users();
  18.  
  19. // read data to active sheet
  20. $this->excel->getActiveSheet()->fromArray($users);
  21.  
  22. $filename='just_some_random_name.xls'; //save our workbook as this file name
  23. header('Content-Type: application/vnd.ms-excel'); //mime type
  24. header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
  25. header('Cache-Control: max-age=0'); //no cache
  26.  
  27. //save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
  28. //if you want to save it as.XLSX Excel 2007 format
  29. $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
  30.  
  31. //force user to download the Excel file without writing it to server's HD
  32. $objWriter->save('php://output');
Maaf, Untuk Memberikan Komentar Anda Harus Login !!!