<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;





	}


	.right{


		text-align: right;


	}


	</style>





 





	<?php





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





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











	// print_r($result);





	?>





 





		<h1>Data PKA</h1>





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





	





 





	<table border="1">





		<tr>





			<th>No</th>





			<th>KMA</th>





			<th>Unit Misioner</th>





			<th>Jenis Kegiatan</th>





			<th>Bidang</th>





			<th>Nama Kegiatan</th>





			<th>Kode Strategi</th>





			<th>Tujuan Kegiatan</th>





			<th>Lokasi Pelaksanaan Program</th>





			<th>Pendukung Program</th>





			<th>Penanggung Jawab</th>





			<th>Waktu Awal Pelaksanaan Program</th>





			<th>Waktu Akhir Pelaksanaan Program</th>





			<th>Indikator Kuantitatif</th>





			<th>Indikator Kualitatif</th>










			<th>Triwulan</th>





			





		





			<th>Pengeluaran</th>





			<th>Penerimaan</th>


			<th>Keterangan</th>





		</tr>





		<?php





		$ttt_peng = 0;





			$ttt_pen = 0;





		$no = 1;





		foreach ($result as $row){





			





			echo "





		<tr>





			<td>".$no++."</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></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>Triwulan $row[triwulan]</td>





			





			





			<td>





				<table border='1'>





					<tr>





						<th>Jenis Pengeluaran</th>





						<th>Jumlah Satuan</th>





						<th>Bulanan</th>





						<th>Tahunan</th>





						<th>Nilai Satuan</th>





						<th>Pengeluaran</th>





					</tr>





				";





				$tot_peng = 0; 





				foreach ($row["data_pengeluaran"] as $data_peng) {





					echo "





					<tr>





						<td>$data_peng[jenis_pengeluaran]</td>





						<td>$data_peng[jumlah_satuan]</td>





						<td>$data_peng[bulanan]</td>





						<td>$data_peng[tahunan]</td>





						<td class='right'>".number_format($data_peng['nilai_satuan'],0,",",",")."</td>





						<td class='right'>".number_format($data_peng['pengeluaran'],0,",",",")."</td>





					</tr>





					";





					$tot_peng += $data_peng["pengeluaran"]; 





				}





				$ttt_peng += $tot_peng;





			echo "





					<tr>





						<td colspan='5'>Total</td>





						<td class='right'>".number_format($tot_peng,0,",",",")."</td>





					</tr>





				</table>





			</td>





			<td>





				<table border='1'>





					<tr>





						<th>Jenis Penerimaan</th>





						<th>Jumlah Satuan</th>





						<th>Bulanan</th>





						<th>Tahunan</th>





						<th>Nilai Satuan</th>





						<th>Penerimaan</th>





					</tr>





				";





				$tot_pen = 0;





				if (!empty($row["data_penerimaan"])) {





				





				foreach ($row["data_penerimaan"] as $data_pen) {





					echo "





					<tr>





						<td>$data_pen[jenis_penerimaan]</td>





						<td>$data_pen[jumlah_satuan]</td>





						<td>$data_pen[bulanan]</td>





						<td>$data_pen[tahunan]</td>





						<td class='right'>".number_format($data_pen['nilai_satuan'],0,",",",")."</td>





						<td class='right'>".number_format($data_pen['penerimaan'],0,",",","),"</td>





					</tr>





					";





					$tot_pen += $data_pen["penerimaan"]; 





				}





				$ttt_pen += $tot_pen;





				}











			echo "





					<tr>





						<td colspan='5'>Total</td>





						<td class='right'>".number_format($tot_pen,0,",",",")."</td>





					</tr>





				</table>





			</td>


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





		</tr>





				





				";





		}





		?>





		<tr>





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


			<td class="right"><?=number_format($ttt_peng,0,",",",")?></td>


			<td class="right"><?=number_format($ttt_pen,0,",",",")?></td>


			<td></td>





		</tr>





	</table>





</body>





</html>