Yii Framework Forum: [SOLVED] Import Excel to CGridView - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

[SOLVED] Import Excel to CGridView Rate Topic: -----

#21 User is offline   mbaksri 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 15-July 11

Posted 27 March 2012 - 03:13 AM

Hi agan putrilangit, saya mau nanya ni.
kalo saya mau export CGridView ke dalam excel kira2 kayak gmn ya?
moga2 aja agan punya saran.. Thanks in Adv. :D
0

#22 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 198
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 27 March 2012 - 10:25 PM

View Postmbaksri, on 27 March 2012 - 03:13 AM, said:

Hi agan putrilangit, saya mau nanya ni.
kalo saya mau export CGridView ke dalam excel kira2 kayak gmn ya?
moga2 aja agan punya saran.. Thanks in Adv. :D


wew , disundul lagi. hehehe :D . Ane pake phpexcel. ^_^
di Controller-nya kyk gini
public function actionGenerateToExcel()
    {
	$model=new Modeldata('search');
        $dataProvider= $model->search();
        $dataProvider->pagination= false; // for retrive all modules
	$data = $dataProvider->data;
		
                foreach ($data as $model)
			{
				$forExcel[]= $model;
			}
		$header = array(
				1 => array ('ID','NAMA','ALAMAT')); // ini headernya ane buat manual. klo gak mau pake header tinggal dihapus aja :D	
						
		Yii::import('application.extensions.phpexcel.JPhpExcel');
		$xls = new JPhpExcel('UTF-8', false, 'DataExcel-worksheet');
		$xls->addArray($header);	
		$xls->addArray($forExcel);	
		$xls->generateXML('FileExcel'.date('Y-m-d'));
    }

Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

#23 User is offline   mbaksri 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 15-July 11

Posted 27 March 2012 - 10:44 PM

View Postputrilangit, on 27 March 2012 - 10:25 PM, said:

wew , disundul lagi. hehehe :D . Ane pake phpexcel. ^_^
di Controller-nya kyk gini
public function actionGenerateToExcel()
    {
	$model=new Modeldata('search');
        $dataProvider= $model->search();
        $dataProvider->pagination= false; // for retrive all modules
	$data = $dataProvider->data;
		
                foreach ($data as $model)
			{
				$forExcel[]= $model;
			}
		$header = array(
				1 => array ('ID','NAMA','ALAMAT')); // ini headernya ane buat manual. klo gak mau pake header tinggal dihapus aja :D	
						
		Yii::import('application.extensions.phpexcel.JPhpExcel');
		$xls = new JPhpExcel('UTF-8', false, 'DataExcel-worksheet');
		$xls->addArray($header);	
		$xls->addArray($forExcel);	
		$xls->generateXML('FileExcel'.date('Y-m-d'));
    }


Nice code Gan.. it works on mine bgt.. tapi niy Gan,, kira2 bisa ga nampilin tabel yg dihasilin dari query? dengan lebih dari satu model jg.. hehe,, thanks in adv. lho Gan.. :D
0

#24 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 198
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 29 March 2012 - 09:25 PM

View Postmbaksri, on 27 March 2012 - 10:44 PM, said:

Nice code Gan.. it works on mine bgt.. tapi niy Gan,, kira2 bisa ga nampilin tabel yg dihasilin dari query? dengan lebih dari satu model jg.. hehe,, thanks in adv. lho Gan.. :D


hehe... ane kurang mudeng pertanyaanya. :D
Tapi secara tidak langsung kan code ane di atas juga query
$model=new Modeldata('search');
$dataProvider= $model->search();
$dataProvider->pagination= false; // for retrive all modules
$data = $dataProvider->data;


atau mau kyk gini juga harusnya bisa.
$DataDari_Model = NamaModel::model()->find('id=:idnya AND nama_lengkap=:namanya',array(':idnya'=>$postID , ':namanya'=>$postNama))
$datanya = $DataDari_Model->attributes;

foreach ($datanya as $row)
{
$forExcel[]= $datanya;
}
$header = array(1 => array ('ID','NAMA','ALAMAT')); // ini headernya ane buat manual. klo gak mau pake header tinggal dihapus aja :D    
                                                
Yii::import('application.extensions.phpexcel.JPhpExcel');
$xls = new JPhpExcel('UTF-8', false, 'DataExcel-worksheet');
$xls->addArray($header);        
$xls->addArray($forExcel);      
$xls->generateXML('FileExcel'.date('Y-m-d'));


kira2 kyk begitu lah . CMIIW ^_^
Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

#25 User is offline   Nur Rochim 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 04-February 13
  • Location:Indonesia

Posted 07 July 2013 - 05:09 AM

Agan NoxoN, bisa berikan contoh script import excel to database punya abang?
0

#26 User is offline   adjie 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 09-April 14

Posted 09 April 2014 - 11:14 PM

gan, tolong kasih tutorialnya yang lengkap
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users