over 11 years ago
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');
- }
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'); }
Can you help out the community by solving one of the following Javascript problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)