Advertisement
GWibisono

hasil akhir yg kuharapkan

May 31st, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.27 KB | None | 0 0
  1. <?php
  2. /*
  3. saya akan buang segala yang menurut saya belum perlu
  4. seperti html.. jadi biarlah tampilannya buruk rupa seperti
  5. wajah saya
  6. */
  7.  
  8. if($_GET['stat']=='open')
  9. {
  10.     header('Content-type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') ;
  11.     $fName='003data.xlsx';
  12.     header('Content-Disposition: attachment; filename="003.xlsx"');
  13.     $f=file_get_contents($fName);
  14.     echo $f;
  15.      
  16.     die();
  17. }
  18.  
  19. if($_POST)
  20. {
  21.     $con = mysql_connect("localhost", "root", "") or
  22.         die("Error: " . mysql_error());
  23.  
  24.  
  25.     mysql_select_db("work_fb2", $con);
  26.     $date=date('Y-m-d',strtotime($_POST['date']) );
  27.     $sql="SELECT
  28.     a.HARI, a.TGL, a.ID_PEL, a.NO_METER,
  29.     a.DY_BR, a.GARDU, a.TIANG, b.NM
  30.     FROM
  31.         td_plg a, tm_plg b
  32.     WHERE
  33.         a.ID_PEL=b.ID_PEL and
  34.         a.TGL like '$date%'";
  35.     $result = mysql_query($sql)or die(mysql_error());
  36.     $a=array(
  37.         array("hari","tanggal","nama","id","no",
  38.         "daya","gardu","tiang")
  39.     );
  40.     /*
  41.     pastikan dari point ini.. tampilannya BENAR!!
  42.      
  43. ?>
  44.           <table width="86%" class="display" id="datatables">
  45.                 <thead>
  46.                     <tr>
  47.                         <th width="58">Hari</th>        
  48.                         <th width="99">Tanggal</th>                                
  49.                         <th width="118">Nama</th>                    
  50.                         <th width="129">Id Pelanggan</th>
  51.                         <th width="145">Nomor Meter</th>
  52.                         <th width="60">Daya</th>
  53.                         <th width="77">Gardu</th>
  54.                         <th width="77">Tiang</th>
  55.                     </tr>
  56.                 </thead>
  57.                 <tbody>
  58.                     <?php
  59.                     */
  60.                     while ($row = mysql_fetch_array($result)) {
  61.                        
  62.                         /*?>
  63.                         <tr>
  64.                             <td><?=$row['HARI']?></td>
  65.                             <td><?=$row['TGL']?></td>
  66.                             <td><?=$row['NM']?></td>
  67.                             <td><?=$row['ID_PEL']?></td>
  68.                             <td><?=$row['NO_METER']?></td>
  69.                             <td><?=$row['DY_BR']?></td>
  70.                             <td><?=$row['GARDU']?></td>
  71.                             <td><?=$row['TIANG']?></td>
  72.                         </tr>
  73.                         <?php
  74.                         */
  75.                         $a1=array(
  76.                             $row['HARI'],
  77.                              $row['TGL'],
  78.                              $row['NM'],
  79.                              $row['ID_PEL'],
  80.                              $row['NO_METER'],
  81.                              $row['DY_BR'],
  82.                              $row['GARDU'],
  83.                             $row['TIANG']
  84.                         );
  85.                            
  86.                         $a[]=$a1;
  87.                     }/*
  88.                     ?>
  89.                 </tbody>
  90.             </table> <?
  91.  
  92.  keluarannya benar.. kalau sudah benar.. ubah script diatas
  93.  buat memakai php-excel
  94.  caranya ubah2 aja jadi fungsi2 yg keluar di php-excel!!
  95. */
  96.     $sType='2007 XLSX';
  97.     error_reporting(E_ALL);
  98.     date_default_timezone_set('Europe/London');
  99.     require_once 'Classes/PHPExcel.php';
  100.     $objPHPExcel = new PHPExcel();
  101.     $objPHPExcel->getProperties()->setCreator("Nasgor")
  102.      ->setLastModifiedBy("Gunawan")
  103.      ->setTitle("Office  Test Document")
  104.      ->setSubject("Office $sType Test Document")
  105.      ->setDescription("Test document for Office $sType, generated using PHP classes.")
  106.      ->setKeywords("office $sType openxml php")
  107.      ->setCategory("Test result file");
  108.      
  109.     for($i=0;$i<=count($a);$i++){
  110.         for($j=0;$j<count($a[$i]);$j++){ //count($aData2)
  111.             $pos=chr(65+$i).($j+1);
  112.             $dt=$a[$i][$j];
  113.            
  114.             $objPHPExcel->setActiveSheetIndex(0)
  115.                 ->setCellValue($pos,$dt );
  116.         }
  117.     }
  118.      
  119.     $objPHPExcel->getActiveSheet()->setTitle('Testing');
  120.  
  121.     $writeAs='Excel2007';
  122.     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $writeAs);
  123.      
  124.     $objWriter->save('003data.xlsx');
  125.      
  126.     header('location:?stat=open');
  127.     die();
  128.  
  129.  
  130. }else{  //if POST?>
  131. <form action="" method="post"
  132.  target='report'>
  133.  <input type=text name='date' > format: 2012-05-10
  134.             <p>
  135.               <input type="submit"   value="Convert Data">
  136.             </p>
  137. </form><?
  138.  }
  139.  
  140.  
  141. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement