Advertisement
GWibisono

perbaikan.. semoga gk ada error

Jun 5th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. kalau benar.. maka inilah hasil akhirnya!! point utama liat yg TERAKHIR!! LOL
  4. */
  5. ob_start();
  6. error_reporting(E_ALL);
  7.  
  8. require_once 'baru/Classes/PHPExcel.php';
  9. // Create new PHPExcel object
  10. $objPHPExcel = new PHPExcel();
  11.  
  12.  
  13. mysql_connect("localhost", "root", "") or die(mysql_error());
  14. mysql_select_db("work_fb2") or die(mysql_error());
  15.  
  16. @isset($_GET['ID_PEL'])?$ID_PEL=$_GET['ID_PEL']:$ID_PEL=0;
  17. echo $ID_PEL;//=$_GET['ID_PEL'];
  18.  
  19. @isset($_GET['TGL'])?$unik = strtotime($_GET['TGL']." 1:0:0") :$unik=0;
  20.  
  21. $tanggal=date('Y-m-d', $unik);
  22.  
  23. $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
  24. where
  25. a.ID_PEL=b.ID_PEL and
  26. a.C_TIM=c.C_TIM and
  27. a.STATUS_KSR=0 and
  28. b.TGL='$tanggal'";
  29.  
  30. $hasil = mysql_query($query)or die($query."<br>".mysql_error());
  31. /*
  32. header dari excel
  33. */
  34. // Set properties
  35. $objPHPExcel->getProperties()->setCreator("Daud Edison Tarigan")
  36. ->setLastModifiedBy("Daud Edison Tarigan")
  37. ->setTitle("Office 2007 XLSX Test Document")
  38. ->setSubject("Office 2007 XLSX Test Document")
  39. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  40. ->setKeywords("office 2007 openxml php")
  41. ->setCategory("Test result file");
  42.  
  43. $a=array();
  44.  //Add some data
  45. /*  
  46. HEADER TULISAN!!
  47. */
  48. $a[5]=array('Data Pelanggan',
  49. 'Nama Tim'
  50. , 'Tanggal'
  51. , 'No'
  52. , 'Nama'
  53. , 'Id Pelanggan'
  54. , 'Nomor Meter'
  55. , 'Daya',
  56. 'Gardu',
  57.  'Tiang'
  58.  );
  59.  
  60. $rowNya = 6;
  61. $no = 0;
  62. while($row=mysql_fetch_array($hasil)){
  63.  
  64.     if($no==0)
  65.         $a[2]=array(1=>$row['C_TIM'],$tanggal);
  66.        
  67.     $no++;  
  68.  
  69.     $i2=$no+5; $a[$i2]=array( $no
  70.     , $row['NM']
  71.     , $row['ID_PEL']."    "
  72.     , $row['NO_METER']."    "
  73.     , $row['DY_BR']
  74.     , $row['GARDU']
  75.     ,$row['TIANG']
  76.     );
  77.     $rowNya = $rowNya + 1;
  78. }
  79.  
  80.  
  81.  
  82. // Rename sheet
  83. $objPHPExcel->getActiveSheet()->setTitle('Simple');
  84.  
  85. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  86. $objPHPExcel->setActiveSheetIndex(0);
  87.  
  88. // Redirect output to a client’s web browser (Excel5)
  89. header('Content-Type: application/vnd.ms-excel');
  90. header('Content-Disposition: attachment;filename="database_plg.xls"');
  91. header('Cache-Control: max-age=0');
  92.  
  93. /*
  94. $s='<table border=0>';
  95. for($i=0;$i<$i2;$i++)
  96. {
  97.     //$s.="\n<tr>";
  98.     for($j=0;$j<7;$j++){
  99.         @is_null($a[$i][$j])?$s.="\n\t<td>&nbsp;</td>":$s.="\n\t<td>".$a[$i][$j]."</td>";
  100.     }
  101.     //$s.="\n</tr>";
  102. }
  103. $s.='</table>';
  104. DIGANTI JADI
  105. */
  106.     for($i=0;$i<=count($a);$i++){
  107.         for($j=0;$j<count($a[$i]);$j++){ //count($aData2)
  108.             $pos=chr(65+$i).($j+1);
  109.             $dt=$a[$i][$j];
  110.             @is_null($a[$i][$j])?$dt='':$dt=$a[$i][$j];
  111.             $objPHPExcel->setActiveSheetIndex(0)
  112.                 ->setCellValue($pos,$dt );
  113.         }
  114.     }
  115. //echo ($s);
  116. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  117. $objWriter->save('php://output');
  118. ?>
  119. <? ob_flush(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement