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

[eluser]Brad K Morse[/eluser]
Corrected code, for application/helper/to_excel_helper.php

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('to_excel')) {
  function to_excel($query, $filename='exceloutput') {
    $headers = ''; // just creating the var for field headers to append to below
    $data = ''; // just creating the var for field data to append to below
    
    $objt =& get_instance();

    $fields = $query->field_data();
    
    if ($query->num_rows() == 0) {
      echo "<p>No data for that report, please use your browser's back button</p>";
      return FALSE;
    } else {
      foreach ($fields as $field) {
        $headers .= $field->name . "\t";
      }

      foreach ($query->result() as $row) {
        $line = '';
        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);

      header("Content-type: application/x-msdownload");
      header("Content-Disposition: attachment; filename=$filename.xls");
      echo "$headers\n$data";  
    }
  }
}
?&gt;


Messages In This Thread
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 04-18-2011, 08:00 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 04-18-2011, 08:02 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 04-18-2011, 08:32 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 04-18-2011, 08:46 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 04-18-2011, 08:47 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 04-18-2011, 08:53 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 04-18-2011, 09:15 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 04-22-2011, 11:24 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 04-22-2011, 11:28 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 04-22-2011, 11:30 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 06-08-2011, 08:01 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 06-08-2011, 08:03 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 06-08-2011, 09:38 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 06-08-2011, 10:22 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 06-08-2011, 01:09 PM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 06-08-2011, 01:39 PM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 06-08-2011, 02:01 PM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 06-08-2011, 02:02 PM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 06-08-2011, 02:05 PM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 06-10-2011, 01:02 PM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 06-10-2011, 01:10 PM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 03-28-2012, 09:23 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 12-27-2013, 03:45 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 12-29-2013, 11:44 AM
converted to_excel plugin to helper to work in CI 2.0 - by El Forum - 12-30-2013, 09:43 PM



Theme © iAndrew 2016 - Forum software by © MyBB