exporttoexcel.php |
1 <?php 2 3 //database 4 $dbhost = "localhost"; 5 $dbuser = "root"; 6 $dbpass = ""; 7 $dbname = "vo2"; 8 9 define("DB_HOST", strip_tags($dbhost)); 10 define("DB_USER", strip_tags($dbuser)); 11 define("DB_PASS", strip_tags($dbpass)); 12 define("DB_NAME", strip_tags($dbname)); 13 14 $chemist = @mysql_connect(DB_HOST,DB_USER,DB_PASS) or die ("Ga bisa konek"); 15 @mysql_select_db(DB_NAME,$chemist) or die ("Database ga ada"); 16 17 //function for XLS 18 function xlsBOF() { 19 echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0); 20 return; 21 } 22 23 function xlsEOF() { 24 echo pack("ss", 0x0A, 0x00); 25 return; 26 } 27 28 function xlsWriteNumber($Row, $Col, $Value) { 29 echo pack("sssss", 0x203, 14, $Row, $Col, 0x0); 30 echo pack("d", $Value); 31 return; 32 } 33 34 function xlsWriteLabel($Row, $Col, $Value ) { 35 $L = strlen($Value); 36 echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L); 37 echo $Value; 38 return; 39 } 40 41 // query database 42 $queabsdetail = "SELECT id, nama, nohp FROM tabel_user";// eksekusi query 43 $exequeabsdetail = mysql_query($queabsdetail);// read the result and insert into new array 44 45 while($res = mysql_fetch_array($exequeabsdetail)){ 46 $data['id'][] = $res['id']; 47 $data['nama'][] = $res['nama']; 48 $data['nohp'][] = $res['nohp']; 49 } $jm = sizeof($data['id']);// sending header 50 51 header("Pragma: public"); 52 header("Expires: 0"); 53 header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 54 header("Content-Type: application/force-download"); 55 header("Content-Type: application/octet-stream"); 56 header("Content-Type: application/download");; 57 header("Content-Disposition: attachment;filename=fileexcel.xls "); 58 header("Content-Transfer-Encoding: binary "); 59 xlsBOF(); 60 xlsWriteLabel(0,0,"Sample : Export To Excel"); 61 xlsWriteLabel(2,0,"Jumlah Data"); 62 xlsWriteLabel(2,1,$jm); 63 xlsWriteLabel(4,1,”No”);//menulis pada cell (baris 4 kolom 1) 64 xlsWriteLabel(4,2,”Nama”); 65 xlsWriteLabel(4,3,”No. Hp”); 66 67 $xlsRow = 5;//posisi awal 68 for ($y=0;$y<$jm;$y++){ //perulangan untuk baca data 69 ++$i; 70 xlsWriteNumber($xlsRow,1,"$i"); 71 xlsWriteLabel($xlsRow,2,$data['nama'][$y]); 72 xlsWriteLabel($xlsRow,3,$data['nohp'][$y]); 73 $xlsRow++; 74 } 75 xlsEOF(); 76 exit(); 77 78 ?> |
78 Lines | Download 'exporttoexcel.php' | 2.2KB |
Powered By GaMerZ File Explorer Version 1.10
Copyright © 2004-2006 Lester "GaMerZ" Chan, All Rights Reserved.
Page Generated In 0.00657 Seconds