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
    • 1.96k
    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:

       
    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: