Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- saya akan buang segala yang menurut saya belum perlu
- seperti html.. jadi biarlah tampilannya buruk rupa seperti
- wajah saya
- */
- if($_GET['stat']=='open')
- {
- header('Content-type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') ;
- $fName='003data.xlsx';
- header('Content-Disposition: attachment; filename="003.xlsx"');
- $f=file_get_contents($fName);
- echo $f;
- die();
- }
- if($_POST)
- {
- $con = mysql_connect("localhost", "root", "") or
- die("Error: " . mysql_error());
- mysql_select_db("work_fb2", $con);
- $date=date('Y-m-d',strtotime($_POST['date']) );
- $sql="SELECT
- a.HARI, a.TGL, a.ID_PEL, a.NO_METER,
- a.DY_BR, a.GARDU, a.TIANG, b.NM
- FROM
- td_plg a, tm_plg b
- WHERE
- a.ID_PEL=b.ID_PEL and
- a.TGL like '$date%'";
- $result = mysql_query($sql)or die(mysql_error());
- $a=array(
- array("hari","tanggal","nama","id","no",
- "daya","gardu","tiang")
- );
- /*
- pastikan dari point ini.. tampilannya BENAR!!
- ?>
- <table width="86%" class="display" id="datatables">
- <thead>
- <tr>
- <th width="58">Hari</th>
- <th width="99">Tanggal</th>
- <th width="118">Nama</th>
- <th width="129">Id Pelanggan</th>
- <th width="145">Nomor Meter</th>
- <th width="60">Daya</th>
- <th width="77">Gardu</th>
- <th width="77">Tiang</th>
- </tr>
- </thead>
- <tbody>
- <?php
- */
- while ($row = mysql_fetch_array($result)) {
- /*?>
- <tr>
- <td><?=$row['HARI']?></td>
- <td><?=$row['TGL']?></td>
- <td><?=$row['NM']?></td>
- <td><?=$row['ID_PEL']?></td>
- <td><?=$row['NO_METER']?></td>
- <td><?=$row['DY_BR']?></td>
- <td><?=$row['GARDU']?></td>
- <td><?=$row['TIANG']?></td>
- </tr>
- <?php
- */
- $a1=array(
- $row['HARI'],
- $row['TGL'],
- $row['NM'],
- $row['ID_PEL'],
- $row['NO_METER'],
- $row['DY_BR'],
- $row['GARDU'],
- $row['TIANG']
- );
- $a[]=$a1;
- }/*
- ?>
- </tbody>
- </table> <?
- keluarannya benar.. kalau sudah benar.. ubah script diatas
- buat memakai php-excel
- caranya ubah2 aja jadi fungsi2 yg keluar di php-excel!!
- */
- $sType='2007 XLSX';
- error_reporting(E_ALL);
- date_default_timezone_set('Europe/London');
- require_once 'Classes/PHPExcel.php';
- $objPHPExcel = new PHPExcel();
- $objPHPExcel->getProperties()->setCreator("Nasgor")
- ->setLastModifiedBy("Gunawan")
- ->setTitle("Office Test Document")
- ->setSubject("Office $sType Test Document")
- ->setDescription("Test document for Office $sType, generated using PHP classes.")
- ->setKeywords("office $sType openxml php")
- ->setCategory("Test result file");
- 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];
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue($pos,$dt );
- }
- }
- $objPHPExcel->getActiveSheet()->setTitle('Testing');
- $writeAs='Excel2007';
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $writeAs);
- $objWriter->save('003data.xlsx');
- header('location:?stat=open');
- die();
- }else{ //if POST?>
- <form action="" method="post"
- target='report'>
- <input type=text name='date' > format: 2012-05-10
- <p>
- <input type="submit" value="Convert Data">
- </p>
- </form><?
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement