Welcome Guest, Not a member yet? Register   Sign In
converted to_excel plugin to helper to work in CI 2.0
#21

[eluser]Brad K Morse[/eluser]
I would assume it is compatible w/ 2007, unfortunately I do not have that installed.
#22

[eluser]Unknown[/eluser]
Please help me,

Fatal error: Call to a member function field_data() on a non-object in C:\xampp\htdocs\sjmm\application\helpers\to_excel_helper.php on line 10

Controller:
Code:
function export($start_date,$end_date)
{
  $file_name = 'Delivery Report';
  $query = $this->Delivery_model->report($start_date,$end_date);
  //print_r($query);
  to_excel($query, $file_name);
}

Model :
Code:
function report($start_date, $end_date)
{
  $this->db->select( '*');
  $this->db->from($this->table);
  $this->db->join('customer', 'del_hdr.cust_id = customer.cust_id', 'INNER');
  $this->db->where('del_hdr.tgl_kirim >=', $start_date);
  $this->db->where('del_hdr.tgl_kirim <=', $end_date);
  $this->db->order_by('del_hdr.tgl_kirim', 'ASC');
  return $this->db->get()->result();
}

I use a helper file that you use the same premises with CI 2.1.0

Any help is appreciated.
#23

[eluser]shivPrasad[/eluser]
HI all, I am newbie in CI.
using to_excel library I'm able to export the file; but the headers are not exported in excel.

Here is To_excel library copied from net:
Code:
/*
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');

|--------------------------------------------------------------------------
| Create Excel file - Library
|--------------------------------------------------------------------------
| Created:  24/04/2013
|
|       Excel library for Code Igniter applications
|       Author: Derek Allard, Dark Horse Consulting, www.darkhorse.to, April 2006
|       https://github.com/EllisLab/CodeIgniter/wiki/Excel-Plugin
|
|       Updated by: ccontreras: 19 May 2011 11:59 AM
|      
|       Updated for Codeigniter 2.1.3  and converted to library file
|       by Timothy Head: 11/06/2013
|
*/
class To_excel {
    
    function create_excel($query, $filename='exceloutput')
    {
        $ci =& get_instance();
        $ci->load->helper('download');
    
        $headers = ''; // just creating the var for field headers to append to below
        $data = ''; // just creating the var for field data to append to below        
  
  
        $fields = $query->list_fields();
  //$fields = $query->field_data();
        if ($query->num_rows() == 0) {
            echo '<p>The table appears to have no data.</p>';
        } else {
            foreach ($fields as $field) {
               //$headers .= $field->name. "\t";
      $headers .= $field. "\t";
            }
    
            foreach ($query->result() as $row) {
                $line = '';
                /*foreach($row as $value) {                                            
                    if (( ! isset($value)) OR ($value == "")) {
                        $value = "\t";
                    } else {
                        $value = str_replace('"', '""', $value);
                        $value = '"' . $value . '"' . "\t";
                    }
                    $line .= $value;
                }
                $data .= trim($line)."\n";
            }*/
   foreach($row as $value) {                                            
     if ((!isset($value)) OR ($value == "")) {
    $value = "\t";
     } else {
    $value = str_replace("\n", " ", $value); // for stupid line breaks that mess up the spreadsheet
    $value = str_replace('"', '""', $value);
    $value = '"' . $value . '"' . "\t";
     }
     $line .= $value;
   }
   $data .= trim($line)."\n";
    }          
            $data = str_replace("\r","",$data);  
            force_download($filename . ".xls", $headers . "\n" . $data);
   /*header("Content-type: application/x-msdownload");
       header("Content-Disposition: attachment; filename=$filename.xls");
      echo "$headers\n$data";*/
        }
    }
}
/* End of file */
/* Location: ./application/libraries/To_excel.php */
Function in the controller :

Code:
public function export($todate,$frmdt,$crite)
{
  //load library
  $this->load->library('To_excel');  
  $this->load->model('admin_model');
  //pass processed query to generate excel file.
  $data = $this->admin_model->reportsPaid($todate,$frmdt,$crite,1);
  // Create Excel file
  
  $this->to_excel->create_excel($data, 'PaidReport'); // filename is optional, without it, the plugin will default to 'exceloutput'
}//

Please guide me on this.
#24

[eluser]Unknown[/eluser]
Might be a mime type problem, make sure server has the appropriate mime types

http://stackoverflow.com/questions/16473...s-on-downl
#25

[eluser]shivPrasad[/eluser]
As per the link given I did following changes in the .htaccess file.
Its my .htaccess file :
Code:
Deny from all
AddType application/vnd.openxmlformats .docx .pptx .xlsx .xltx . xltm .dotx .potx .ppsx .xls

but still its not working.. Sad

is there any mistake in controller or Library file??




Theme © iAndrew 2016 - Forum software by © MyBB