Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Programatically Creating Custom csv files in Magento

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.03k
    Comment on it

    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:

    1. public function createcsvAction(){
    2. $param = $this->getRequest()->getPost();
    3. $csv = '';
    4. $_columns = array(
    5. "Shop Number",
    6. "Shop Name",
    7. "Total Sales ",
    8. "Orders Sum" ,
    9. "Orders Average ",
    10. "Total Year To Date Sales ",
    11. "Year To Date Orders Sum" ,
    12. "Year To Date Orders Average"
    13.  
    14. );
    15. $data = array();
    16. // prepare CSV header...
    17. foreach ($_columns as $column) {
    18. $data[] = '"'.$column.'"';
    19. }
    20. $csv .= implode(',', $data)."\n";
    21. $data = array();
    22. $data[] = $param['shopno'];
    23. $data[] = $param['shopname'];
    24. $data[] = $param['totalsale'];
    25. $data[] = $param['ordersum'];
    26. $data[] = $param['orderavg'];
    27. $data[] = $param['yearsale'];
    28. $data[] = $param['yeartotalsum'];
    29. $data[] = $param['yearavg'];
    30. //...
    31. $csv .= implode(',', $data)."\n";
    32. //now $csv varaible has csv data as string
    33. $this->_redirect('*/*/');
    34. $this->_prepareDownloadResponse('Export_sales_report.csv', $csv, 'text/csv');
    35. }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: