thom_

PHP TO EXCEL

May 28th, 2012
34
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php  
  2. /*
  3. Code by Tim Simpus
  4. For further information about this software, please contact:
  5. Raharjo (masjojok@gmail.com), or
  6. Albert (albert.pratama@gmail.com)
  7. */
  8. class XlsdiagnosiComponent extends Object
  9. {
  10.     function excel($content){
  11.         $export_file = "excel.xls";
  12.         $fp = fopen($export_file, "wb");
  13.         if (!is_resource($fp)){die("Cannot open $export_file");}
  14.         fwrite($fp, $content);
  15.         fclose($fp);
  16.         header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  17.         header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
  18.         header ("Cache-Control: no-cache, must-revalidate");
  19.         header ("Pragma: no-cache");
  20.         header ("Content-type: application/x-msexcel");
  21.         header ("Content-Disposition: attachment; filename=\"" . basename($export_file) . "\"" );
  22.         header ("Content-Description: PHP/INTERBASE Generated Data" );
  23.         readfile($export_file);
  24.     }
  25.    
  26.     function nominal($num){
  27.         $data = (number_format($num, 0, ',', '.'));
  28.         return $data;
  29.     }
  30.    
  31.     function date_for_mysql($ref){
  32.         $tanggal = explode("-",$ref);
  33.         if(empty($tanggal[0]) || empty($tanggal[1]) || empty($tanggal[2]))
  34.             $tanggal = "";
  35.         else
  36.             $tanggal = $tanggal[2]."-".$tanggal[1]."-".$tanggal[0];
  37.         return $tanggal;
  38.     }
  39.  
  40.     function diagnosispasien($datas,$tgl1,$tgl2,$filter){
  41.         $content = "
  42.             <h2>DATA DIAGNOSIS PASIEN RUMAH SAKIT</h2>
  43.             Periode : ".$tgl1." s/d ".$tgl2."<br>";
  44.         if(!empty($filter)){
  45.             foreach($filter AS $filter2){
  46.                 $content .= $filter2[0]." ".$filter2[1]." ".$filter2[2]."<br>";
  47.             }
  48.         }
  49.         $content .= "
  50.             <table class='grid' border='1'>
  51.                 <tr>
  52.                     <th>No Registrasi</th>
  53.                     <th>Kode Diagnosi</th>
  54.                     <th>Diagnosis</th>
  55.                     <th>ICDX</th>
  56.                     <th>Tanggal</th>
  57.                     <th>Nama</th>
  58.                     <th>Nama KK</th>
  59.                     <th>Suku</th>
  60.                     <th>Pekerjaan</th>
  61.                     <th>Dusun</th>
  62.                     <th>Desa</th>
  63.                     <th>Asal Pasien</th>
  64.                     <th>Tempat Periksa</th>
  65.                     <th>Petugas</th>
  66.                     <th>JK</th>
  67.                     <th>Kelompok<br>Umur</th>
  68.                     <th>Pengirim</th>
  69.                     <th>Diagnosi Kasus</th>
  70.                     <th>Jenis<br>Pasien</th>
  71.                     <th>Tindak<br>Lanjut</th>
  72.                     <th>Hari</th>
  73.                     <th>Bulan</th>
  74.                     <th>Tahun</th>
  75.                     <th>Unit</th>
  76.                     <th>Poli Rujuk</th>
  77.                     <th>Rumah Sakit</th>
  78.                     <th>Wilayah</th>
  79.                     <th>Kartu Sehat</th>
  80.                     <th>Kepesertaan</th>
  81.                 </tr>";
  82.         if(!empty($datas)){
  83.             foreach ($datas as $data){
  84.                 $content .= "<tr><td align='right'>".$data['Visit']['id']."</td>";
  85.                 $content .= "<td>".$data['Diagnosi']['disease_id']."</td>";
  86.                 $content .= "<td>".$data['Disease']['nama']."</td>";
  87.                 $content .= "<td>".$data['Disease']['icdx']."</td>";
  88.                 $content .= "<td>".$this->date_for_mysql($data['Visit']['tanggal'])."</td>";
  89.                 $content .= "<td>".$data['Visit']['nama']."</td>";
  90.                 $content .= "<td>".$data['Visit']['nama_kk']."</td>";
  91.                 $content .= "<td>".$data['Tribe']['suku']."</td>";
  92.                 $content .= "<td>".$data['Work']['pekerjaan']."</td>";
  93.                 $content .= "<td>".$data['Orchard']['dusun']."</td>";
  94.                 $content .= "<td>".$data['Village']['desa']."</td>";
  95.                 $content .= "<td>".$data['Asal']['desa']."</td>";
  96.                 $content .= "<td>".$data['Poscheck']['nama']."</td>";
  97.                 $content .= "<td>".$data['Worker']['nama']."</td>";
  98.                 $content .= "<td>".$data['Sex']['singkatan']."</td>";
  99.                 $content .= "<td>".$data['Groupage']['kelompok_umur']."</td>";
  100.                 $content .= "<td>".$data['Consignor']['pengirim']."</td>";
  101.                 $content .= "<td>".$data['Groupvisit']['kelompok_kunjungan']."</td>";
  102.                 $content .= "<td>".$data['Typepatient']['jenis']."</td>";
  103.                 $content .= "<td>".$data['Action']['tindak_lanjut']."</td>";
  104.                 $content .= "<td align='right'>".$data['Visit']['harilahir']."</td>";
  105.                 $content .= "<td align='right'>".$data['Visit']['bulanlahir']."</td>";
  106.                 $content .= "<td align='right'>".$data['Visit']['umur']."</td>";
  107.                 $content .= "<td>".$data['Unit']['unit']."</td>";
  108.                 $content .= "<td>".$data['Polireference']['polirujukan']."</td>";
  109.                 $content .= "<td>".$data['Hospital']['rs']."</td>";
  110.                 $content .= "<td>".(($data['Village']['wilayah'] == 'T') ? 'Dalam Wilayah' : 'Luar Wilayah')."</td>";
  111.                 $content .= "<td>".$data['Visit']['no_kartu']."</td>";
  112.                 $content .= "<td>".$data['Visit']['kepesertaan']."</td></tr>";
  113.             }
  114.         }
  115.         $content .= "</table>";
  116.         $this->excel($content);
  117.     }
  118. }
  119.   ?>
RAW Paste Data