<?php
	include_once('admincp/modules/connect.php');
	include_once('Classes/PHPExcel.php');

	if(isset($_POST['btnExport'])){
		$objExcel = new PHPExcel;
		$objExcel->setActiveSheetIndex(0);
		$sheet = $objExcel ->getActiveSheet()->setTitle('2011');
		$rowCount = 1;
		$sheet->setCellValue('A'.$rowCount, 'STT');
		$sheet->setCellValue('B'.$rowCount, 'Hộp số');
		$sheet->setCellValue('C'.$rowCount, 'Mã hồ sơ');
		$sheet->setCellValue('D'.$rowCount, 'Chủ sử dụng');
		$sheet->setCellValue('E'.$rowCount, 'Năm cấp');
		$sheet->setCellValue('F'.$rowCount, 'Loại hồ sơ');
		$sheet->setCellValue('G'.$rowCount, 'Số thửa');
		$sheet->setCellValue('H'.$rowCount, 'Tờ bản đồ');
		$sheet->setCellValue('I'.$rowCount, 'Mã loại đất');
		$sheet->setCellValue('J'.$rowCount, 'Loại thửa');
		$sheet->setCellValue('K'.$rowCount, 'Mục lục');
		$sql = "SELECT * FROM hoso";
		$result = mysql_query($sql);
		while($row = mysql_fetch_array($result)){
			$rowCount++;
			$sheet->setCellValue('A'.$rowCount, $row['idhoso']);
			$sheet->setCellValue('B'.$rowCount, $row['hopso']);
			$sheet->setCellValue('C'.$rowCount, $row['mahoso']);
			$sheet->setCellValue('D'.$rowCount, $row['chusudung']);
			$sheet->setCellValue('E'.$rowCount, $row['namcap']);
			$sheet->setCellValue('F'.$rowCount, $row['loaihoso']);
			$sheet->setCellValue('G'.$rowCount, $row['sothua']);
			$sheet->setCellValue('H'.$rowCount, $row['tobando']);
			$sheet->setCellValue('I'.$rowCount, $row['maloaidat']);
			$sheet->setCellValue('J'.$rowCount, $row['loaithua']);
			$sheet->setCellValue('K'.$rowCount, $row['mucluc']);
		}

		$objWriter = new PHPExcel_Writer_Excel2007($objExcel);
		$filename = 'export.pdf';
		$objWriter->save($filename);
		
		header('Content-Disposition: attachment; filename="' . $filename . '"');
		header('Content-Type: application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet');
		header('Content-Length:'. filesize($filename));
		header('Content-Transfer-Encoding: binary');
		header('Cache-Control: must-revalidate');
		header('Pragma:no-cache');
		readfile($filename);
		return;		
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
	<form method="POST">
		<button type="submit" name="btnExport">Export file</button>
	</form>

</body>
</html>