<html>


<head>


	<title>Export Data Ke Excel Dengan PHP</title>


</head>


<body>


	<style type="text/css">


	body{


		font-family: sans-serif;


	}


	table{


		margin: 20px auto;


		border-collapse: collapse;


	}


	table th,


	table td{


		border: 1px solid #3c3c3c;


		padding: 3px 8px;


		


 


	}


	table td{


		vertical-align: top;


	}


	a{


		background: blue;


		color: #fff;


		padding: 8px 10px;


		text-decoration: none;


		border-radius: 2px;


	}


	</style>


 


	<?php


	header("Content-type: application/vnd-ms-excel");


	header("Content-Disposition: attachment; filename=Data_PKA_admin".$periode.".xls");





	// print_r($result);


	if(empty($result)){


	    echo "<h1>Data PKA Kosong</h1>";


	}else{


	?>


 


		<h1>Data PKA</h1>


		<p>Periode : <?=$periode?></p>


	


 


	<table border="1">


		<tr>


			<th rowspan="2">No</th>


			<!-- <th>Periode Tahun</th> -->


			<th rowspan="2">KMA</th>


			<th rowspan="2">Unit Misioner</th>


			<th rowspan="2">Jenis Kegiatan</th>


			<th rowspan="2">Bidang</th>


			<th rowspan="2">Nama Kegiatan</th>


			<th rowspan="2">Kode Strategi</th>


			<th rowspan="2">Tujuan Kegiatan</th>


			<th rowspan="2">Lokasi Pelaksanaan Program</th>


			<th rowspan="2">Pendukung Program</th>


			<th rowspan="2">Penanggung Jawab</th>


			<th rowspan="2">Waktu Awal Pelaksanaan Program</th>


			<th rowspan="2">Waktu Akhir Pelaksanaan Program</th>


			<th rowspan="2">Indikator Kuantitatif</th>


			<th rowspan="2">Indikator Kualitatif</th>


			<th rowspan="2">Prioritas Kegiatan</th>


			<!-- <th rowspan="2">Triwulan</th> -->


			




			


			<th rowspan="2">Keterangan</th>


			


			<th colspan="5" style='background:#b2f7c3;'>Triwulan</th>


			<th colspan="4" style='background:#bfcadb;'>Penerimaan</th>


			<th colspan="4" style='background:#fcc48b;'>Pengeluaran</th>


			<th rowspan="2" style='background:#bfcadb;'>Total Penerimaan</th>


			<th rowspan="2" style='background:#fcc48b;'>Total Pengeluaran</th>


			


		</tr>


		<tr>


			<th style='background:#b2f7c3;'>Chek</th>


			<th style='background:#b2f7c3;'>1</th>


			<th style='background:#b2f7c3;'>2</th>


			<th style='background:#b2f7c3;'>3</th>


			<th style='background:#b2f7c3;'>4</th>





			<th style='background:#bfcadb;'>Triwulan 1</th>


			<th style='background:#bfcadb;'>Triwulan 2</th>


			<th style='background:#bfcadb;'>Triwulan 3</th>


			<th style='background:#bfcadb;'>Triwulan 4</th>


			<th style='background:#fcc48b;'>Triwulan 1</th>


			<th style='background:#fcc48b;'>Triwulan 2</th>


			<th style='background:#fcc48b;'>Triwulan 3</th>


			<th style='background:#fcc48b;'>Triwulan 4</th>


		</tr>


		<?php


		$ttt_peng = 0;


			$ttt_pen = 0;


		$no = 1;


		foreach ($result as $row){


			$pengeluaran = $row['pengeluaran'] == 0? "-" : "".$row['pengeluaran'];


			$penerimaan = $row['penerimaan'] == 0? "-" : "".$row['penerimaan'];





			$pen_t1 = $row['pen_t1'] == 0? "-" : "".$row['pen_t1'];

			$pen_t2 = $row['pen_t2'] == 0? "-" : "".$row['pen_t2'];


			$pen_t3 = $row['pen_t3'] == 0? "-" : "".$row['pen_t3'];


			$pen_t4 = $row['pen_t4'] == 0? "-" : "".$row['pen_t4'];





			//$peng_t1 = $row['peng_t1'] == 0? "-" : "".number_format($row['peng_t1'],0,",",",");
			$peng_t1 = $row['peng_t1'] == 0? "-" : "".$row['peng_t1'];


			$peng_t2 = $row['peng_t2'] == 0? "-" : "".$row['peng_t2'];


			$peng_t3 = $row['peng_t3'] == 0? "-" : "".$row['peng_t3'];


			$peng_t4 = $row['peng_t4'] == 0? "-" : "".$row['peng_t4'];





			echo "


		<tr>


			<td>".$no++."</td>".


			// <td>$row[periode_thn]</td>


			"


			<td>$row[kma]</td>


			<td>$row[nm_um]</td>


			<td>$row[nm_jk]</td>


			<td>$row[nm_b]</td>


			<td>$row[nama_kegiatan]</td>


			<td>Kode : $row[kode_strategi]<br><br>Head : $row[head]"./*<br><br>Ket : $row[s_ket]*/"</td>


			<td>$row[tujuan_kegiatan]</td>


			<td>$row[lokasi_pp]</td>


			<td>$row[pendukung_program]</td>


			<td>$row[pen_jawab_program]</td>


			<td>$row[w_awal_pp_case]</td>


			<td>$row[w_akhir_pp_case]</td>


			<td>$row[indikator_kuantitatif]</td>


			<td>$row[indikator_kualitatif]</td>


			<td>$row[nm_pk]</td>".


			// <td>Triwulan $row[triwulan]</td>


			"

			


			<td>$row[ket]</td>


			<td style='text-align: center;background:#b2f7c3;'>$row[chek_tw]</td>


			<td style='text-align: center;background:#b2f7c3;'>$row[tw1]</td>


			<td style='text-align: center;background:#b2f7c3;'>$row[tw2]</td>


			<td style='text-align: center;background:#b2f7c3;'>$row[tw3]</td>


			<td style='text-align: center;background:#b2f7c3;'>$row[tw4]</td>





			<td style='text-align:right;background:#bfcadb;'>$pen_t1</td>


			<td style='text-align:right;background:#bfcadb;'>$pen_t2</td>


			<td style='text-align:right;background:#bfcadb;'>$pen_t3</td>


			<td style='text-align:right;background:#bfcadb;'>$pen_t4</td>


			<td style='text-align:right;background:#fcc48b;'>$peng_t1</td>


			<td style='text-align:right;background:#fcc48b;'>$peng_t2</td>


			<td style='text-align:right;background:#fcc48b;'>$peng_t3</td>


			<td style='text-align:right;background:#fcc48b;'>$peng_t4</td>


			<td style='text-align:right;background:#bfcadb;'>$penerimaan</td>


			<td style='text-align:right;background:#fcc48b;'>$pengeluaran</td>


			


		</tr>


				


				";


		}








		?>


		<tr>


			<td colspan="17">TOTAL</td>


			<td colspan="5" style='text-align: center;background:#b2f7c3;'></td>





			<td style='text-align:right;background:#bfcadb;'><strong><?= $tot_pen_t1 ?></strong></td>


			<td style='text-align:right;background:#bfcadb;'><strong><?= $tot_pen_t2 ?></strong></td>


			<td style='text-align:right;background:#bfcadb;'><strong><?= $tot_pen_t3 ?></strong></td>


			<td style='text-align:right;background:#bfcadb;'><strong><?= $tot_pen_t4 ?></strong></td>





			<td style='text-align:right;background:#fcc48b;'><strong><?= $tot_peng_t1 ?></strong></td>


			<td style='text-align:right;background:#fcc48b;'><strong><?= $tot_peng_t2 ?></strong></td>


			<td style='text-align:right;background:#fcc48b;'><strong><?= $tot_peng_t3 ?></strong></td>


			<td style='text-align:right;background:#fcc48b;'><strong><?= $tot_peng_t4 ?></strong></td>





			<td style='text-align:right;background:#bfcadb;'><strong><?= $tot_pen ?></strong></td>


			<td style='text-align:right;background:#fcc48b;'><strong><?= $tot_peng ?></strong></td>


		</tr>


	</table>


	<?php }?>


</body>


</html>