I am using fputcsv to create a csv but the data it outputs starts on the 3rd row when i open it in excel. Why is this?
I want to create a row of column headers using fputcsv, what is the best way to do this.?
public function indexAction()
{
$this->outputCSV();
//$this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')->getNavigation('passport_admin_main', array(), 'passport_admin_main_outofarea');
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
header('Content-Disposition: attachment; filename="OutOfAreaReport.csv"');
header('Content-type: application/excel');
readfile('OutOfAreaReport.csv');
}
public function outputCSV(){
$list = array (
array('aaa', 'saasasbbb', 'ccdddc', 'dddd')
);
$fp = fopen('php://output', 'w');
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
}