Welcome Guest, Not a member yet? Register   Sign In
Why When Exporting Data to CSV do I get empty rows on the CSV ?
#1

[eluser]vincej[/eluser]
Hi - My export works fine. The only odd thing is that I get 8 empty rows when opening in Excel 2010. I have used the same code in other parts of my site to export other data and I get the same thing. I have in my my head that I was not getting this in Excel 2003. Weird or what ?

I'd like to get rid of the empty rows.

Many Thanks for your advice !

controller:

Code:
function exportsales(){
   $this->load->helper('download');
   $csv = $this->MReports->exportSalesCsv();
   $name = "sales_export.csv";
   force_download($name,$csv);
   }

Model

Code:
function exportSalesCsv(){
$startdate = strtotime($this->session->userdata('startdate'));
$enddate = strtotime($this->session->userdata('enddate'));

if ((!empty($startdate)) && (!empty($enddate))){
  $this->load->dbutil();
  $startdate = db_clean($startdate);
  $enddate = db_clean($enddate);
  $Q = $this->db->query(
"SELECT products.name, confirmedorder.prodid, sum(confirmedorder.quantity) as 'Quantity', sum(confirmedorder.ordervalue) as 'Order Value'
FROM `products`, `confirmedorder`
        where confirmedorder.prodid = products.id
     AND confirmedorder.sale = 'closed'
AND date >= $startdate
AND date <=$enddate
        group by confirmedorder.prodid;");
return $this->dbutil->csv_from_result($Q,",","\n");
    }

   }




Theme © iAndrew 2016 - Forum software by © MyBB