It's simple to create custom csv in magento .
follow the steps to create custom csv.
Create a controller to access data that you want to export in csv file like as below:
public function createcsvAction(){
$param = $this->getRequest()->getPost();
$csv = '';
$_columns = array(
"Shop Number",
"Shop Name",
"Total Sales ",
"Orders Sum" ,
"Orders Average ",
"Total Year To Date Sales ",
"Year To Date Orders Sum" ,
"Year To Date Orders Average"
);
$data = array();
// prepare CSV header...
foreach ($_columns as $column) {
$data[] = '"'.$column.'"';
}
$csv .= implode(',', $data)."\n";
$data = array();
$data[] = $param['shopno'];
$data[] = $param['shopname'];
$data[] = $param['totalsale'];
$data[] = $param['ordersum'];
$data[] = $param['orderavg'];
$data[] = $param['yearsale'];
$data[] = $param['yeartotalsum'];
$data[] = $param['yearavg'];
//...
$csv .= implode(',', $data)."\n";
//now $csv varaible has csv data as string
$this->_redirect('*/*/');
$this->_prepareDownloadResponse('Export_sales_report.csv', $csv, 'text/csv');
}
0 Comment(s)