Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- kalau benar.. maka inilah hasil akhirnya!! point utama liat yg TERAKHIR!! LOL
- */
- ob_start();
- error_reporting(E_ALL);
- require_once 'baru/Classes/PHPExcel.php';
- // Create new PHPExcel object
- $objPHPExcel = new PHPExcel();
- mysql_connect("localhost", "root", "") or die(mysql_error());
- mysql_select_db("work_fb2") or die(mysql_error());
- @isset($_GET['ID_PEL'])?$ID_PEL=$_GET['ID_PEL']:$ID_PEL=0;
- echo $ID_PEL;//=$_GET['ID_PEL'];
- @isset($_GET['TGL'])?$unik = strtotime($_GET['TGL']." 1:0:0") :$unik=0;
- $tanggal=date('Y-m-d', $unik);
- $query = "SELECT a.NM, b.ID_PEL, b.NO_METER, b.DY_BR, b.GARDU, b.TIANG, b.TGL, c.C_TIM FROM tm_plg a, td_plg b, t_tim c
- where
- a.ID_PEL=b.ID_PEL and
- a.C_TIM=c.C_TIM and
- a.STATUS_KSR=0 and
- b.TGL='$tanggal'";
- $hasil = mysql_query($query)or die($query."<br>".mysql_error());
- /*
- header dari excel
- */
- // Set properties
- $objPHPExcel->getProperties()->setCreator("Daud Edison Tarigan")
- ->setLastModifiedBy("Daud Edison Tarigan")
- ->setTitle("Office 2007 XLSX Test Document")
- ->setSubject("Office 2007 XLSX Test Document")
- ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
- ->setKeywords("office 2007 openxml php")
- ->setCategory("Test result file");
- $a=array();
- //Add some data
- /*
- HEADER TULISAN!!
- */
- $a[5]=array('Data Pelanggan',
- 'Nama Tim'
- , 'Tanggal'
- , 'No'
- , 'Nama'
- , 'Id Pelanggan'
- , 'Nomor Meter'
- , 'Daya',
- 'Gardu',
- 'Tiang'
- );
- $rowNya = 6;
- $no = 0;
- while($row=mysql_fetch_array($hasil)){
- if($no==0)
- $a[2]=array(1=>$row['C_TIM'],$tanggal);
- $no++;
- $i2=$no+5; $a[$i2]=array( $no
- , $row['NM']
- , $row['ID_PEL']." "
- , $row['NO_METER']." "
- , $row['DY_BR']
- , $row['GARDU']
- ,$row['TIANG']
- );
- $rowNya = $rowNya + 1;
- }
- // Rename sheet
- $objPHPExcel->getActiveSheet()->setTitle('Simple');
- // Set active sheet index to the first sheet, so Excel opens this as the first sheet
- $objPHPExcel->setActiveSheetIndex(0);
- // Redirect output to a client’s web browser (Excel5)
- header('Content-Type: application/vnd.ms-excel');
- header('Content-Disposition: attachment;filename="database_plg.xls"');
- header('Cache-Control: max-age=0');
- /*
- $s='<table border=0>';
- for($i=0;$i<$i2;$i++)
- {
- //$s.="\n<tr>";
- for($j=0;$j<7;$j++){
- @is_null($a[$i][$j])?$s.="\n\t<td> </td>":$s.="\n\t<td>".$a[$i][$j]."</td>";
- }
- //$s.="\n</tr>";
- }
- $s.='</table>';
- DIGANTI JADI
- */
- for($i=0;$i<=count($a);$i++){
- for($j=0;$j<count($a[$i]);$j++){ //count($aData2)
- $pos=chr(65+$i).($j+1);
- $dt=$a[$i][$j];
- @is_null($a[$i][$j])?$dt='':$dt=$a[$i][$j];
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue($pos,$dt );
- }
- }
- //echo ($s);
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- $objWriter->save('php://output');
- ?>
- <? ob_flush(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement