devilangel Posted March 18, 2012 Share Posted March 18, 2012 Hello, guys i got some issue in my script for exporting data to CSV (exel for view) Its export all data in one collumn, but i need to export each data in separeta column like. a B a1 ID ID2 But i got there this: a B a1 ID""ID2 Here is the script: <?php class WDealAdminExport extends UWidgetWorklet { public function accessRules() { return array( array('allow', 'roles' => array('company')), array('deny', 'users'=>array('*')) ); } public function taskConfig() { $list = wm()->get('deal.admin.coupon'); $_GET[$list->modelClassName] = $_POST[$list->modelClassName]; $list->init(); $dataProvider = $list->dataProvider(); $dataProvider->pagination = false; $csv = array( array( $this->t('ID'), $this->t('Order ID'), $this->t('Deal ID'), $this->t('User'), $this->t('Status'), ) ); foreach($dataProvider->data as $data) { $row = array( "#".$data->couponId(), $data->orderId, $data->dealId, $data->user->email." [".$data->user->getName(true)."]", $data->status==1 ? ($data->deal->isExpired() ? $this->t('Expired') : $this->t('Available')) : $this->t('Used') ); if($_POST['charset'] != 'utf-8') { $row[3] = iconv('utf-8', $_POST['charset'], $row[3]); $row[4] = iconv('utf-8', $_POST['charset'], $row[4]); } $csv[] = $row; } $contents = $this->generateCSV($csv); $this->send($contents); } public function taskGenerateCSV($src) { $csv = ''; foreach($src as $row) { foreach($row as $item) $csv.= $this->escape($item).$this->param('delimiter'); $csv = rtrim($csv,$this->param('delimiter'))."\r\n"; } return $csv; } public function taskEscape($value) { return '"'.str_replace('"','""',$value).'"'; } public function taskSend($contents) { $content_type = "application/octet-stream"; $filename = 'export.csv'; // disable browser caching header('Cache-control: private'); header('Pragma: private'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Content-Type: '.$content_type); header('Content-Transfer-Encoding: binary'); header('Content-Length: '.strlen($contents)); header('Content-Disposition: attachment;filename="'.$filename.'"'); echo $contents; app()->end(); } } Quote Link to comment https://forums.phpfreaks.com/topic/259194-need-help-for-exporting-scriprt-to-csv/ Share on other sites More sharing options...
trq Posted March 18, 2012 Share Posted March 18, 2012 What? Quote Link to comment https://forums.phpfreaks.com/topic/259194-need-help-for-exporting-scriprt-to-csv/#findComment-1328705 Share on other sites More sharing options...
devilangel Posted March 18, 2012 Author Share Posted March 18, 2012 Script exports data from database, to exel... But thing is , that it exports all data in one cell I need somehow export this info from database to saparete cells 1 cell for id , 1 cell for order id etc $csv = array( array( $this->t('ID'), $this->t('Order ID'), $this->t('Deal ID'), $this->t('User'), $this->t('Status'), ) ); Quote Link to comment https://forums.phpfreaks.com/topic/259194-need-help-for-exporting-scriprt-to-csv/#findComment-1328713 Share on other sites More sharing options...
downah Posted March 18, 2012 Share Posted March 18, 2012 You need to export your database to CSV? Quote Link to comment https://forums.phpfreaks.com/topic/259194-need-help-for-exporting-scriprt-to-csv/#findComment-1328734 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.