SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | - | /* |
| 2 | + | /* |
| 3 | - | saya akan buang segala yang menurut saya belum perlu |
| 3 | + | kalau benar.. maka inilah hasil akhirnya!! point utama liat yg TERAKHIR!! LOL |
| 4 | - | seperti html.. jadi biarlah tampilannya buruk rupa seperti |
| 4 | + | |
| 5 | - | wajah saya |
| 5 | + | ob_start(); |
| 6 | error_reporting(E_ALL); | |
| 7 | ||
| 8 | - | if($_GET['stat']=='open') |
| 8 | + | require_once 'baru/Classes/PHPExcel.php'; |
| 9 | // Create new PHPExcel object | |
| 10 | - | header('Content-type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') ;
|
| 10 | + | $objPHPExcel = new PHPExcel(); |
| 11 | - | $fName='003data.xlsx'; |
| 11 | + | |
| 12 | - | header('Content-Disposition: attachment; filename="003.xlsx"');
|
| 12 | + | |
| 13 | - | $f=file_get_contents($fName); |
| 13 | + | mysql_connect("localhost", "root", "") or die(mysql_error());
|
| 14 | - | echo $f; |
| 14 | + | mysql_select_db("work_fb2") or die(mysql_error());
|
| 15 | - | |
| 15 | + | |
| 16 | - | die(); |
| 16 | + | @isset($_GET['ID_PEL'])?$ID_PEL=$_GET['ID_PEL']:$ID_PEL=0; |
| 17 | - | } |
| 17 | + | echo $ID_PEL;//=$_GET['ID_PEL']; |
| 18 | ||
| 19 | - | if($_POST) |
| 19 | + | @isset($_GET['TGL'])?$unik = strtotime($_GET['TGL']." 1:0:0") :$unik=0; |
| 20 | ||
| 21 | - | $con = mysql_connect("localhost", "root", "") or
|
| 21 | + | $tanggal=date('Y-m-d', $unik);
|
| 22 | - | die("Error: " . mysql_error());
|
| 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 | - | mysql_select_db("work_fb2", $con);
|
| 25 | + | a.ID_PEL=b.ID_PEL and |
| 26 | - | $date=date('Y-m-d',strtotime($_POST['date']) );
|
| 26 | + | a.C_TIM=c.C_TIM and |
| 27 | - | $sql="SELECT |
| 27 | + | a.STATUS_KSR=0 and |
| 28 | - | a.HARI, a.TGL, a.ID_PEL, a.NO_METER, |
| 28 | + | b.TGL='$tanggal'"; |
| 29 | - | a.DY_BR, a.GARDU, a.TIANG, b.NM |
| 29 | + | |
| 30 | - | FROM |
| 30 | + | $hasil = mysql_query($query)or die($query."<br>".mysql_error()); |
| 31 | - | td_plg a, tm_plg b |
| 31 | + | /* |
| 32 | - | WHERE |
| 32 | + | header dari excel |
| 33 | - | a.ID_PEL=b.ID_PEL and |
| 33 | + | |
| 34 | - | a.TGL like '$date%'"; |
| 34 | + | // Set properties |
| 35 | - | $result = mysql_query($sql)or die(mysql_error()); |
| 35 | + | $objPHPExcel->getProperties()->setCreator("Daud Edison Tarigan")
|
| 36 | - | $a=array( |
| 36 | + | ->setLastModifiedBy("Daud Edison Tarigan")
|
| 37 | - | array("hari","tanggal","nama","id","no",
|
| 37 | + | ->setTitle("Office 2007 XLSX Test Document")
|
| 38 | - | "daya","gardu","tiang") |
| 38 | + | ->setSubject("Office 2007 XLSX Test Document")
|
| 39 | ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
| |
| 40 | - | /* |
| 40 | + | ->setKeywords("office 2007 openxml php")
|
| 41 | - | pastikan dari point ini.. tampilannya BENAR!! |
| 41 | + | ->setCategory("Test result file");
|
| 42 | - | |
| 42 | + | |
| 43 | - | ?> |
| 43 | + | $a=array(); |
| 44 | - | <table width="86%" class="display" id="datatables"> |
| 44 | + | //Add some data |
| 45 | - | <thead> |
| 45 | + | /* |
| 46 | - | <tr> |
| 46 | + | HEADER TULISAN!! |
| 47 | - | <th width="58">Hari</th> |
| 47 | + | |
| 48 | - | <th width="99">Tanggal</th> |
| 48 | + | $a[5]=array('Data Pelanggan',
|
| 49 | - | <th width="118">Nama</th> |
| 49 | + | 'Nama Tim' |
| 50 | - | <th width="129">Id Pelanggan</th> |
| 50 | + | , 'Tanggal' |
| 51 | - | <th width="145">Nomor Meter</th> |
| 51 | + | , 'No' |
| 52 | - | <th width="60">Daya</th> |
| 52 | + | , 'Nama' |
| 53 | - | <th width="77">Gardu</th> |
| 53 | + | , 'Id Pelanggan' |
| 54 | - | <th width="77">Tiang</th> |
| 54 | + | , 'Nomor Meter' |
| 55 | - | </tr> |
| 55 | + | , 'Daya', |
| 56 | - | </thead> |
| 56 | + | 'Gardu', |
| 57 | - | <tbody> |
| 57 | + | 'Tiang' |
| 58 | - | <?php |
| 58 | + | ); |
| 59 | - | */ |
| 59 | + | |
| 60 | - | while ($row = mysql_fetch_array($result)) {
|
| 60 | + | $rowNya = 6; |
| 61 | - | |
| 61 | + | $no = 0; |
| 62 | - | /*?> |
| 62 | + | while($row=mysql_fetch_array($hasil)){
|
| 63 | - | <tr> |
| 63 | + | |
| 64 | - | <td><?=$row['HARI']?></td> |
| 64 | + | if($no==0) |
| 65 | - | <td><?=$row['TGL']?></td> |
| 65 | + | $a[2]=array(1=>$row['C_TIM'],$tanggal); |
| 66 | - | <td><?=$row['NM']?></td> |
| 66 | + | |
| 67 | - | <td><?=$row['ID_PEL']?></td> |
| 67 | + | $no++; |
| 68 | - | <td><?=$row['NO_METER']?></td> |
| 68 | + | |
| 69 | - | <td><?=$row['DY_BR']?></td> |
| 69 | + | $i2=$no+5; $a[$i2]=array( $no |
| 70 | - | <td><?=$row['GARDU']?></td> |
| 70 | + | , $row['NM'] |
| 71 | - | <td><?=$row['TIANG']?></td> |
| 71 | + | , $row['ID_PEL']." " |
| 72 | - | </tr> |
| 72 | + | , $row['NO_METER']." " |
| 73 | - | <?php |
| 73 | + | , $row['DY_BR'] |
| 74 | - | */ |
| 74 | + | , $row['GARDU'] |
| 75 | - | $a1=array( |
| 75 | + | ,$row['TIANG'] |
| 76 | - | $row['HARI'], |
| 76 | + | |
| 77 | - | $row['TGL'], |
| 77 | + | $rowNya = $rowNya + 1; |
| 78 | - | $row['NM'], |
| 78 | + | } |
| 79 | - | $row['ID_PEL'], |
| 79 | + | |
| 80 | - | $row['NO_METER'], |
| 80 | + | |
| 81 | - | $row['DY_BR'], |
| 81 | + | |
| 82 | - | $row['GARDU'], |
| 82 | + | // Rename sheet |
| 83 | - | $row['TIANG'] |
| 83 | + | $objPHPExcel->getActiveSheet()->setTitle('Simple');
|
| 84 | - | ); |
| 84 | + | |
| 85 | - | |
| 85 | + | // Set active sheet index to the first sheet, so Excel opens this as the first sheet |
| 86 | - | $a[]=$a1; |
| 86 | + | $objPHPExcel->setActiveSheetIndex(0); |
| 87 | - | }/* |
| 87 | + | |
| 88 | - | ?> |
| 88 | + | // Redirect output to a client’s web browser (Excel5) |
| 89 | - | </tbody> |
| 89 | + | header('Content-Type: application/vnd.ms-excel');
|
| 90 | - | </table> <? |
| 90 | + | header('Content-Disposition: attachment;filename="database_plg.xls"');
|
| 91 | header('Cache-Control: max-age=0');
| |
| 92 | - | keluarannya benar.. kalau sudah benar.. ubah script diatas |
| 92 | + | |
| 93 | - | buat memakai php-excel |
| 93 | + | /* |
| 94 | - | caranya ubah2 aja jadi fungsi2 yg keluar di php-excel!! |
| 94 | + | $s='<table border=0>'; |
| 95 | for($i=0;$i<$i2;$i++) | |
| 96 | - | $sType='2007 XLSX'; |
| 96 | + | |
| 97 | - | error_reporting(E_ALL); |
| 97 | + | //$s.="\n<tr>"; |
| 98 | - | date_default_timezone_set('Europe/London');
|
| 98 | + | for($j=0;$j<7;$j++){
|
| 99 | - | require_once 'Classes/PHPExcel.php'; |
| 99 | + | @is_null($a[$i][$j])?$s.="\n\t<td> </td>":$s.="\n\t<td>".$a[$i][$j]."</td>"; |
| 100 | - | $objPHPExcel = new PHPExcel(); |
| 100 | + | } |
| 101 | - | $objPHPExcel->getProperties()->setCreator("Nasgor")
|
| 101 | + | //$s.="\n</tr>"; |
| 102 | - | ->setLastModifiedBy("Gunawan")
|
| 102 | + | } |
| 103 | - | ->setTitle("Office Test Document")
|
| 103 | + | $s.='</table>'; |
| 104 | - | ->setSubject("Office $sType Test Document")
|
| 104 | + | DIGANTI JADI |
| 105 | - | ->setDescription("Test document for Office $sType, generated using PHP classes.")
|
| 105 | + | |
| 106 | - | ->setKeywords("office $sType openxml php")
|
| 106 | + | |
| 107 | - | ->setCategory("Test result file");
|
| 107 | + | |
| 108 | - | |
| 108 | + | |
| 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 | - | |
| 113 | + | |
| 114 | } | |
| 115 | //echo ($s); | |
| 116 | $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); | |
| 117 | $objWriter->save('php://output');
| |
| 118 | - | |
| 118 | + | ?> |
| 119 | - | $objPHPExcel->getActiveSheet()->setTitle('Testing');
|
| 119 | + | <? ob_flush(); ?> |