SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | error_reporting(E_ALL); | |
| 3 | require_once 'baru/Classes/PHPExcel.php'; | |
| 4 | // Create new PHPExcel object | |
| 5 | $objPHPExcel = new PHPExcel(); | |
| 6 | ||
| 7 | mysql_connect("localhost", "root", "root") or die(mysql_error());
| |
| 8 | mysql_select_db("pln2") or die(mysql_error());
| |
| 9 | $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"; | |
| 10 | $hasil = mysql_query($query); | |
| 11 | ||
| 12 | // Set properties | |
| 13 | $objPHPExcel->getProperties()->setCreator("Daud Edison Tarigan")
| |
| 14 | ->setLastModifiedBy("Daud Edison Tarigan")
| |
| 15 | ->setTitle("Office 2007 XLSX Test Document")
| |
| 16 | ->setSubject("Office 2007 XLSX Test Document")
| |
| 17 | ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
| |
| 18 | ->setKeywords("office 2007 openxml php")
| |
| 19 | ->setCategory("Test result file");
| |
| 20 | /* | |
| 21 | Tulisan awal menunnjukkan Office 2k7 jgn dipaksa dibuka di 2k ato 2k3 | |
| 22 | ||
| 23 | */ | |
| 24 | ||
| 25 | // Add some data | |
| 26 | $objPHPExcel->setActiveSheetIndex(0) | |
| 27 | ->setCellValue('A3', 'No')
| |
| 28 | ->setCellValue('B3', 'Nama')
| |
| 29 | ->setCellValue('C3', 'Id Pelanggan')
| |
| 30 | ->setCellValue('D3', 'Nomor Meter')
| |
| 31 | ->setCellValue('E3', 'Daya')
| |
| 32 | ->setCellValue('F3', 'Gardu')
| |
| 33 | ->setCellValue('G3', 'Tiang');
| |
| 34 | ||
| 35 | $rowNya = 4; | |
| 36 | $no = 0; | |
| 37 | while($row=mysql_fetch_array($hasil)){
| |
| 38 | $no = $no +1; | |
| 39 | $objPHPExcel->setActiveSheetIndex(0) | |
| 40 | ->setCellValue("A$rowNya", $no)
| |
| 41 | ->setCellValue("B$rowNya", $row['NM'])
| |
| 42 | - | ->setCellValue("C$rowNya", ' '.$row['ID_PEL']."\n" )
|
| 42 | + | ->setCellValue("C$rowNya", $row['ID_PEL']." " )
|
| 43 | - | ->setCellValue("D$rowNya", ' '.$row['NO_METER']."\n")
|
| 43 | + | ->setCellValue("D$rowNya", $row['NO_METER']." " )
|
| 44 | ->setCellValue("E$rowNya", $row['DY_BR'])
| |
| 45 | ->setCellValue("F$rowNya", $row['GARDU'])
| |
| 46 | ->setCellValue("G$rowNya", $row['TIANG']);
| |
| 47 | $rowNya++; | |
| 48 | $objPHPExcel->setActiveSheetIndex(0) | |
| 49 | ->setCellValue("A$rowNya", "Nama Tim :".$row['C_TIM'])
| |
| 50 | ->setCellValue("B$rowNya", "Tanggal :".$row['TGL']);
| |
| 51 | } | |
| 52 | - | ->setCellValue("B$rowNya", "Tanggal :".$row['TGL'])
|
| 52 | + | |
| 53 | ||
| 54 | // Rename sheet | |
| 55 | $objPHPExcel->getActiveSheet()->setTitle('Simple');
| |
| 56 | ||
| 57 | // Set active sheet index to the first sheet, so Excel opens this as the first sheet | |
| 58 | $objPHPExcel->setActiveSheetIndex(0); | |
| 59 | ||
| 60 | /* | |
| 61 | Redirect output to a client’s web browser (Excel5) | |
| 62 | header('Content-Type: application/vnd.ms-excel');
| |
| 63 | */ | |
| 64 | header('Content-type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') ;
| |
| 65 | header('Content-Disposition: attachment;filename="database_plg.xlsx"');
| |
| 66 | header('Cache-Control: max-age=0');
| |
| 67 | ||
| 68 | $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); | |
| 69 | $objWriter->save('php://output');
| |
| 70 | exit; | |
| 71 | ?> |