<?php

include_once ("includes/setup.inc.php");

$dateTimeNow = dateTimeNow();
$ladang = $_POST['ladang'];
$TITLE = $_POST['title'];

$color_tidak_berkenaan = 'F2F4F4';
$color_ladang_ruminan = 'FCF3CF';
$color_ladang_tenusu = 'D5F5E3';
$color_ladang_babi = 'FADBD8';
$color_ladang_aneka = 'D6EAF8';

$indicator_Query = "SELECT A.*, B.*, C.desk_jantina, D.desk_bangsa, F.desk_dun, G.desk_parlimen, H.desk_daerah, i_negeri.desk_negeri,
					i_status_ladang.desk_status_ladang, i_projek_kerajaan.desk_projek_kerajaan, i_katpemilik.desk_katpemilik,
					i_status_lesen.desk_status_lesen, i_sistem_pemeliharaan.desk_sistem_pemeliharaan, i_hakmilik.desk_hakmilik,
					i_kategori_tanah.desk_kategori_tanah, i_syarat_nyata_tanah.desk_syarat_nyata_tanah,
					m_ladang_ruminan.*, m_ladang_tenusu.*, m_ladang_babi.*, m_ladang_aneka.*
					FROM m_ladang A
					LEFT JOIN m_pemilik B ON B.id_pemilik = A.id_pemilik
					LEFT JOIN i_jantina C ON C.id_jantina = B.id_jantina
					LEFT JOIN i_bangsa D ON D.id_bangsa = B.id_bangsa
					LEFT JOIN i_dun F ON F.id_dun = A.id_dun
					LEFT JOIN i_parlimen G ON G.id_parlimen = A.id_parlimen
					LEFT JOIN i_daerah H ON H.id_daerah = A.id_daerah
					LEFT JOIN i_negeri ON i_negeri.id_negeri = A.id_negeri
					LEFT JOIN i_status_ladang ON i_status_ladang.id_status_ladang = A.id_status_ladang
					LEFT JOIN i_projek_kerajaan ON i_projek_kerajaan.id_projek_kerajaan = A.id_projek_kerajaan
					LEFT JOIN i_katpemilik ON i_katpemilik.id_katpemilik = A.id_katpemilik
					LEFT JOIN i_status_lesen ON i_status_lesen.id_status_lesen = A.id_status_lesen
					LEFT JOIN i_sistem_pemeliharaan ON i_sistem_pemeliharaan.id_sistem_pemeliharaan = A.id_sistem_pemeliharaan
					LEFT JOIN i_hakmilik ON i_hakmilik.id_hakmilik = A.id_hakmilik
					LEFT JOIN i_kategori_tanah ON i_kategori_tanah.id_kategori_tanah = A.id_kategori_tanah
					LEFT JOIN i_syarat_nyata_tanah ON i_syarat_nyata_tanah.id_syarat_nyata_tanah = A.id_syarat_nyata_tanah
					LEFT JOIN m_ladang_ruminan ON m_ladang_ruminan.id_ladang_ruminan = A.id_ladang_ruminan
					LEFT JOIN m_ladang_tenusu ON m_ladang_tenusu.id_ladang_tenusu = A.id_ladang_tenusu
					LEFT JOIN m_ladang_babi ON m_ladang_babi.id_ladang_babi = A.id_ladang_babi
					LEFT JOIN m_ladang_aneka ON m_ladang_aneka.id_ladang_aneka = A.id_ladang_aneka
					
					";
if($ladang == 1)
{
	$indicator_Query .= " WHERE A.id_ladang_ruminan > 0 ";
	$TITLE .= " (Ladang Ruminan)";
}
else if($ladang == 2)
{
	$indicator_Query .= " WHERE A.id_ladang_tenusu > 0 ";
	$TITLE .= " (Ladang Tenusu)";
}
else if($ladang == 3)
{
	$indicator_Query .= " WHERE A.id_ladang_babi > 0 ";
	$TITLE .= " (Ladang Babi)";
}
else if($ladang == 4)
{
	$indicator_Query .= " WHERE A.id_ladang_aneka > 0 ";
	$TITLE .= " (Ladang Aneka Haiwan)";
}
else
{
	$TITLE .= " (Semua)";
}
$indicator_Query .= " order by A.id_ladang ";

$PDO_stmt = $PDO->prepare($indicator_Query); 
$PDO_stmt->execute();
$dataArray = [];
while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
{
	$dataArray[] = $result;
}

$headerTitle = [];
$headerTitle[] = array('BIL');
$headerTitle[] = array('NAMA PEMILIK / TUAN PUNYA');
$headerTitle[] = array('NAMA PENTERNAK');
$headerTitle[] = array('NO. K/P (BARU)');
$headerTitle[] = array('TAHUN');
$headerTitle[] = array('BULAN');
$headerTitle[] = array('HARI');
$headerTitle[] = array('TARIKH LAHIR');
$headerTitle[] = array('4 DIGIT TERAKHIR');
$headerTitle[] = array('JANTINA');
$headerTitle[] = array('UMUR');
$headerTitle[] = array('BANGSA');
$headerTitle[] = array('STATUS BUMIPUTERA');
$headerTitle[] = array('NO. TELEFON');
$headerTitle[] = array('ALAMAT RUMAH/ PEJABAT');
$headerTitle[] = array('ID PREMIS (nyatakan)');
$headerTitle[] = array('ALAMAT PREMIS / LADANG');
$headerTitle[] = array('GPS (Pintu masuk premis)');
$headerTitle[] = array('NEGERI');
$headerTitle[] = array('DAERAH');
$headerTitle[] = array('MUKIM');
$headerTitle[] = array('PARLIMEN');
$headerTitle[] = array('DUN');
$headerTitle[] = array('STATUS');
$headerTitle[] = array('PROJEK KERAJAAN');
$headerTitle[] = array('KATEGORI PEMILIK / TUAN PUNYA');
$headerTitle[] = array('STATUS PELESENAN (jika berkenaan)');
$headerTitle[] = array('SISTEM PEMELIHARAAN');
$headerTitle[] = array('HAK MILIK TANAH');
$headerTitle[] = array('KATEGORI TANAH');
$headerTitle[] = array('SYARAT NYATA TANAH');

$ruminanTitle = [];
$count_ruminan = 0;
if($ladang == 0 || $ladang == 1)
{
	$ruminanTitle['LUAS LADANG (ekar)'][] = 'KANDANG';
	$ruminanTitle['LUAS LADANG (ekar)'][] = 'FODDER';
	$ruminanTitle['LUAS LADANG (ekar)'][] = 'RAGUTAN';
	$ruminanTitle['KAPASITI LADANG (ekor)'][] = 'LEMBU PEDAGING';
	$ruminanTitle['KAPASITI LADANG (ekor)'][] = 'LEMBU FIDLOT';
	$ruminanTitle['KAPASITI LADANG (ekor)'][] = 'KAMBING';
	$ruminanTitle['KAPASITI LADANG (ekor)'][] = 'BEBIRI';
	$ruminanTitle['KAPASITI LADANG (ekor)'][] = 'KERBAU';
	$ruminanTitle['KATEGORI LADANG (INDUK)'][] = 'LEMBU PEDAGING';
	$ruminanTitle['KATEGORI LADANG (INDUK)'][] = 'KAMBING/BEBIRI';
	$ruminanTitle['KATEGORI LADANG (INDUK)'][] = 'KERBAU';

	$ruminanTitle['BILANGAN TERNAKAN LEMBU KK'][] = 'BAKA KK';
	$ruminanTitle['BILANGAN TERNAKAN LEMBU KK'][] = 'JURUSAN (Pedaging)';
	$ruminanTitle['BILANGAN TERNAKAN LEMBU KK'][] = 'JANTAN < 1 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN LEMBU KK'][] = 'JANTAN 1-2 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN LEMBU KK'][] = 'JANTAN > 2 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN LEMBU KK'][] = 'BETINA < 1 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN LEMBU KK'][] = 'BETINA 1-2 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN LEMBU KK'][] = 'BETINA > 2 TAHUN';

	$ruminanTitle['BILANGAN TERNAKAN LEMBU KACUKAN'][] = 'BAKA KACUKAN';
	$ruminanTitle['BILANGAN TERNAKAN LEMBU KACUKAN'][] = 'JURUSAN (Pedaging)';
	$ruminanTitle['BILANGAN TERNAKAN LEMBU KACUKAN'][] = 'JANTAN < 1 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN LEMBU KACUKAN'][] = 'JANTAN 1-2 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN LEMBU KACUKAN'][] = 'JANTAN > 2 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN LEMBU KACUKAN'][] = 'BETINA < 1 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN LEMBU KACUKAN'][] = 'BETINA 1-2 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN LEMBU KACUKAN'][] = 'BETINA > 2 TAHUN';

	$ruminanTitle['BILANGAN TERNAKAN KERBAU'][] = 'BAKA (Sawah / Murrah)';
	$ruminanTitle['BILANGAN TERNAKAN KERBAU'][] = 'JURUSAN (Pedaging)';
	$ruminanTitle['BILANGAN TERNAKAN KERBAU'][] = 'JANTAN < 1 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN KERBAU'][] = 'JANTAN 1-2 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN KERBAU'][] = 'JANTAN > 2 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN KERBAU'][] = 'BETINA < 1 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN KERBAU'][] = 'BETINA 1-2 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN KERBAU'][] = 'BETINA > 2 TAHUN';

	$ruminanTitle['BILANGAN TERNAKAN KAMBING'][] = 'BAKA (Tempatan / Kacukan)';
	$ruminanTitle['BILANGAN TERNAKAN KAMBING'][] = 'JURUSAN (Pedaging)';
	$ruminanTitle['BILANGAN TERNAKAN KAMBING'][] = 'JANTAN < 1 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN KAMBING'][] = 'JANTAN > 1 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN KAMBING'][] = 'BETINA < 1 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN KAMBING'][] = 'BETINA > 1 TAHUN';

	$ruminanTitle['BILANGAN TERNAKAN BEBIRI'][] = 'BAKA';
	$ruminanTitle['BILANGAN TERNAKAN BEBIRI'][] = 'JURUSAN (Pedaging)';
	$ruminanTitle['BILANGAN TERNAKAN BEBIRI'][] = 'JANTAN < 1 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN BEBIRI'][] = 'JANTAN > 1 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN BEBIRI'][] = 'BETINA < 1 TAHUN';
	$ruminanTitle['BILANGAN TERNAKAN BEBIRI'][] = 'BETINA > 1 TAHUN';

	$ruminanTitle['PENDAPATAN LEMBU'][] = 'BIL. TERNAKAN DIJUAL (Ekor)';
	$ruminanTitle['PENDAPATAN LEMBU'][] = 'NILAI JUALAN PER EKOR (RM)';
	$ruminanTitle['PENDAPATAN KERBAU'][] = 'BIL. TERNAKAN DIJUAL (Ekor)';
	$ruminanTitle['PENDAPATAN KERBAU'][] = 'NILAI JUALAN PER EKOR (RM)';
	$ruminanTitle['PENDAPATAN KAMBING'][] = 'BIL. TERNAKAN DIJUAL (Ekor)';
	$ruminanTitle['PENDAPATAN KAMBING'][] = 'NILAI JUALAN PER EKOR (RM)';
	$ruminanTitle['PENDAPATAN BEBIRI'][] = 'BIL. TERNAKAN DIJUAL (Ekor)';
	$ruminanTitle['PENDAPATAN BEBIRI'][] = 'NILAI JUALAN PER EKOR (RM)';
	
	$count_ruminan = count($ruminanTitle, 1) - count($ruminanTitle);
}

$tenusuTitle = [];
$count_tenusu = 0;
if($ladang == 0 || $ladang == 2)
{
	$tenusuTitle['LUAS LADANG (ekar)'][] = 'KANDANG';
	$tenusuTitle['LUAS LADANG (ekar)'][] = 'FODDER';
	$tenusuTitle['LUAS LADANG (ekar)'][] = 'RAGUTAN';
	
	$tenusuTitle['KAPASITI LADANG (ekor)'][] = 'LEMBU';
	$tenusuTitle['KAPASITI LADANG (ekor)'][] = 'KERBAU';
	$tenusuTitle['KAPASITI LADANG (ekor)'][] = 'KAMBING';
	$tenusuTitle['KAPASITI LADANG (ekor)'][] = 'BEBIRI';
	
	$tenusuTitle['KATEGORI LADANG'][] = 'KATEGORI LADANG';
	
	$tenusuTitle['BILANGAN TERNAKAN LEMBU'][] = 'BAKA (KK/ Kacukan)';
	$tenusuTitle['BILANGAN TERNAKAN LEMBU'][] = 'JANTAN < 1 TAHUN';
	$tenusuTitle['BILANGAN TERNAKAN LEMBU'][] = 'JANTAN 1-2 TAHUN';
	$tenusuTitle['BILANGAN TERNAKAN LEMBU'][] = 'JANTAN > 2 TAHUN';
	$tenusuTitle['BILANGAN TERNAKAN LEMBU'][] = 'BETINA < 1 TAHUN';
	$tenusuTitle['BILANGAN TERNAKAN LEMBU'][] = 'BETINA 1-2 TAHUN';
	$tenusuTitle['BILANGAN TERNAKAN LEMBU'][] = 'BETINA > 2 TAHUN';
	
	$tenusuTitle['BILANGAN TERNAKAN KERBAU'][] = 'BAKA (Sawah / Murrah)';
	$tenusuTitle['BILANGAN TERNAKAN KERBAU'][] = 'JANTAN < 1 TAHUN';
	$tenusuTitle['BILANGAN TERNAKAN KERBAU'][] = 'JANTAN 1-2 TAHUN';
	$tenusuTitle['BILANGAN TERNAKAN KERBAU'][] = 'JANTAN > 2 TAHUN';
	$tenusuTitle['BILANGAN TERNAKAN KERBAU'][] = 'BETINA < 1 TAHUN';
	$tenusuTitle['BILANGAN TERNAKAN KERBAU'][] = 'BETINA 1-2 TAHUN';
	$tenusuTitle['BILANGAN TERNAKAN KERBAU'][] = 'BETINA > 2 TAHUN';
	
	$tenusuTitle['BILANGAN TERNAKAN KAMBING'][] = 'BAKA (Tempatan / Kacukan)';
	$tenusuTitle['BILANGAN TERNAKAN KAMBING'][] = 'JANTAN < 1 TAHUN';
	$tenusuTitle['BILANGAN TERNAKAN KAMBING'][] = 'JANTAN > 1 TAHUN';
	$tenusuTitle['BILANGAN TERNAKAN KAMBING'][] = 'BETINA < 1 TAHUN';
	$tenusuTitle['BILANGAN TERNAKAN KAMBING'][] = 'BETINA > 1 TAHUN';
	
	$tenusuTitle['PENDAPATAN (JUALAN TERNAKAN)'][] = 'BIL. TERNAKAN DIJUAL (Ekor)';
	$tenusuTitle['PENDAPATAN (JUALAN TERNAKAN)'][] = 'NILAI JUALAN PER EKOR (RM)';
	$tenusuTitle['PENDAPATAN (JUALAN TERNAKAN)'][] = 'NILAI PENDAPATAN PER TAHUN (RM)';
	
	$tenusuTitle['PENDAPATAN (JUALAN SUSU) LEMBU'][] = 'JUMLAH PENGELUARAN SUSU/ HARI (LITER)';
	$tenusuTitle['PENDAPATAN (JUALAN SUSU) LEMBU'][] = 'NILAI JUALAN (RM/LITER)';
	$tenusuTitle['PENDAPATAN (JUALAN SUSU) LEMBU'][] = 'NILAI PENDAPATAN PER TAHUN (RM)';
	
	$tenusuTitle['PENDAPATAN (JUALAN SUSU) KAMBING'][] = 'JUMLAH PENGELUARAN SUSU/ HARI (LITER)';
	$tenusuTitle['PENDAPATAN (JUALAN SUSU) KAMBING'][] = 'NILAI JUALAN (RM/LITER)';
	$tenusuTitle['PENDAPATAN (JUALAN SUSU) KAMBING'][] = 'NILAI PENDAPATAN PER TAHUN (RM)';
	
	$count_tenusu = count($tenusuTitle, 1) - count($tenusuTitle);
}

$babiTitle = [];
$count_babi = 0;
if($ladang == 0 || $ladang == 3)
{
	$babiTitle['LUAS LADANG (Ha)'][] = 'LUAS LADANG';
	$babiTitle['KAPASITI PER KANDANG'][] = 'KAPASITI';
	
	$babiTitle['BAKA'][] = 'BAKA';
	$babiTitle['SISTEM PERUMAHAN/ KANDANG'][] = 'KANDANG TERTUTUP';
	$babiTitle['SISTEM PERUMAHAN/ KANDANG'][] = 'KANDANG SEMI TERBUKA';
	$babiTitle['SISTEM PERUMAHAN/ KANDANG'][] = 'KANDANG TERBUKA';
	
	$babiTitle['PENGURUSAN SISA KUMBAHAN'][] = 'JUMLAH SISA KUMBAHAN';
	$babiTitle['PENGURUSAN SISA KUMBAHAN'][] = 'JENIS PENGOLAHAN';
	$babiTitle['PENGURUSAN SISA KUMBAHAN'][] = 'ZON PENAMPAN MIN 200 METER';
	$babiTitle['PENGURUSAN SISA KUMBAHAN'][] = 'PENGAMALAN GAHP';
	$babiTitle['PENGURUSAN SISA KUMBAHAN'][] = 'HOMEMIXER';

	$babiTitle['SPESIS TERNAKAN'][] = 'PEJANTAN / BOAR';
	$babiTitle['SPESIS TERNAKAN'][] = 'INDUK / SOW (SSP)';
	$babiTitle['SPESIS TERNAKAN'][] = 'LAIN-LAIN';
	$babiTitle['SPESIS TERNAKAN'][] = 'JUMLAH SPP';
	
	$babiTitle['PENDAPATAN'][] = ' BIL. PENGELUARAN (EKOR)';
	$babiTitle['PENDAPATAN'][] = 'NILAI JUALAN PER EKOR (RM)';
	$babiTitle['PENDAPATAN'][] = 'JUMLAH PENDAPATAN (RM)';
	
	$count_babi = count($babiTitle, 1) - count($babiTitle);
}

$anekaTitle = [];
$count_aneka = 0;
if($ladang == 0 || $ladang == 4)
{
	$anekaTitle['BIL KANDANG'][] = 'BIL KANDANG';
	$anekaTitle['KAPASITI KANDANG'][] = 'KAPASITI KANDANG';
	$anekaTitle['LUAS TANAH (KAKI/ EKAR)'][] = 'KAWASAN PENGELUARAN';
	$anekaTitle['LUAS TANAH (KAKI/ EKAR)'][] = 'KAWASAN LADANG';

	$anekaTitle['BILANGAN TERNAKAN ARNAB'][] = 'PEDAGING';
	$anekaTitle['BILANGAN TERNAKAN ARNAB'][] = 'PET';
	$anekaTitle['BILANGAN TERNAKAN RUSA'][] = 'PEDAGING JANTAN';
	$anekaTitle['BILANGAN TERNAKAN RUSA'][] = 'PEDAGING BETINA';
	$anekaTitle['BILANGAN TERNAKAN RUSA'][] = 'REKREASI JANTAN';
	$anekaTitle['BILANGAN TERNAKAN RUSA'][] = 'REKREASI BETINA';
	$anekaTitle['BILANGAN TERNAKAN KUDA'][] = 'PEMBIAKAN JANTAN';
	$anekaTitle['BILANGAN TERNAKAN KUDA'][] = 'PEMBIAKAN BETINA';
	$anekaTitle['BILANGAN TERNAKAN KUDA'][] = 'REKREASI JANTAN';
	$anekaTitle['BILANGAN TERNAKAN KUDA'][] = 'REKREASI GELDING';
	$anekaTitle['BILANGAN TERNAKAN KUDA'][] = 'REKREASI BETINA';
	$anekaTitle['BILANGAN TERNAKAN KATAK'][] = 'KATAK';
	$anekaTitle['BILANGAN TERNAKAN LAIN-LAIN UNGGAS (EKOR)'][] = 'ANGSA';
	$anekaTitle['BILANGAN TERNAKAN LAIN-LAIN UNGGAS (EKOR)'][] = 'AYAM PIRU';
	$anekaTitle['BILANGAN TERNAKAN LAIN-LAIN UNGGAS (EKOR)'][] = 'OSTRICH';
	$anekaTitle['BILANGAN TERNAKAN LAIN-LAIN UNGGAS (EKOR)'][] = 'AYAM SELASIH';
	$anekaTitle['BILANGAN TERNAKAN LAIN-LAIN UNGGAS (EKOR)'][] = 'AYAM MUTIARA';
	$anekaTitle['BILANGAN TERNAKAN LAIN-LAIN UNGGAS (EKOR)'][] = 'PARROT';
	$anekaTitle['PENDAPATAN'][] = ' BIL. TERNAKAN DIJUAL (EKOR)';
	$anekaTitle['PENDAPATAN'][] = 'NILAI JUALAN PER EKOR (RM)';
	
	$count_aneka = count($anekaTitle, 1) - count($anekaTitle);
}

$AUTHOR = (($my_details->fullname=='')?'admin_'.$my_details->usr_id:$my_details->fullname);
$FILE_NAME = str_replace(' : ', '_', $TITLE).'_'.date("d_m_Y");
$FILE_NAME = str_replace(' ', '_', $FILE_NAME).'_'.date("d_m_Y");
$PAGE_ORIENTATION = $_POST['pageOrientation'];
$myTitle = $TITLE;
//------------------------------------------------------------------------------------------------------------------------

	/** Error reporting */
	error_reporting(0);
	ini_set('display_errors', TRUE);
	ini_set('display_startup_errors', TRUE);
	date_default_timezone_set('Europe/London');

	if (PHP_SAPI == 'cli')
		die('This example should only be run from a Web Browser');

	/** Include PHPExcel */
	require_once 'classes/PHPExcel.php';

	// Create new PHPExcel object
	$objPHPExcel = new PHPExcel();

	// Set document properties
	$objPHPExcel->getProperties()->setCreator($AUTHOR)
								 ->setLastModifiedBy($AUTHOR)
								 ->setTitle($TITLE)
								 ->setSubject($TITLE)
								 ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
								 ->setKeywords("office 2007 openxml $TITLE")
								 ->setCategory("Test result file");

								 
	//set default style
	$objPHPExcel->getDefaultStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
	
	// Add data
	//One can use the possibility to access cell values by column and row index like (0,1) instead of 'A1' for reading and writing cell values in loops.
	//In PHPExcel column index is 0-based while row index is 1-based. That means 'A1' ~ (0,1)
	$objPHPExcel->setActiveSheetIndex(0);
	$ROW_INDEX = 1; //use this to control row indexing
	
	//set anything before print table
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $ROW_INDEX++, $myTitle);
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $ROW_INDEX++, count($headerTitle));
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $ROW_INDEX++, $count_ruminan);
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $ROW_INDEX++, $count_tenusu);
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $ROW_INDEX++, count($dataArray));
	$ROW_INDEX++; //move to next row
	$ROW_INDEX++; //move to next row

	//print table header
	$START_COLUMN = 0; //normally start at 0
	$END_COLUMN = count($headerTitle) + $count_ruminan + $count_tenusu + $count_babi + $count_aneka - 1 + $START_COLUMN; //based on number of header
	
	$START_COLUMN_ALPHABET = PHPExcel_Cell::stringFromColumnIndex($START_COLUMN); //convert to alphabet
	$END_COLUMN_ALPHABET = PHPExcel_Cell::stringFromColumnIndex($END_COLUMN); //convert to alphabet
	
	$START_ROW = $ROW_INDEX; //keep a record of start row of table
	
	$myCol = $START_COLUMN;
	for( $num = 0 ; $num < count($headerTitle) ; $num++ )
	{
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $ROW_INDEX, $headerTitle[$num][0]);
		$objPHPExcel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex($myCol).$ROW_INDEX.':'.PHPExcel_Cell::stringFromColumnIndex($myCol).($ROW_INDEX + 2));
		$myCol++;
	}
	$startCategoryRow = $ROW_INDEX;
	$ROW_INDEX++;
	
	if($count_ruminan > 0)
	{
		$startCategoryCol = $myCol;
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $startCategoryRow, 'LADANG RUMINAN');
		$ROW_INDEX = $startCategoryRow + 1;
		foreach($ruminanTitle as $key=>$value)
		{
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $ROW_INDEX, $key);
			$startCol = $myCol;
			foreach($value as $key2=>$value2)
			{
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $ROW_INDEX + 1, $value2);
				$myCol++;
			}
			$objPHPExcel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex($startCol).$ROW_INDEX.':'.PHPExcel_Cell::stringFromColumnIndex($myCol - 1).($ROW_INDEX));
		}
		$objPHPExcel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex($startCategoryCol).$startCategoryRow.':'.PHPExcel_Cell::stringFromColumnIndex($myCol - 1).($startCategoryRow));
		$objPHPExcel->getActiveSheet()
				->getStyle(PHPExcel_Cell::stringFromColumnIndex($startCategoryCol).$startCategoryRow.':'.PHPExcel_Cell::stringFromColumnIndex($myCol - 1).($startCategoryRow + 2))
				->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB ($color_ladang_ruminan)  ;
	}
	
	if($count_tenusu > 0)
	{
		$startCategoryCol = $myCol;
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $startCategoryRow, 'LADANG TENUSU');
		$ROW_INDEX = $startCategoryRow + 1;
		foreach($tenusuTitle as $key=>$value)
		{
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $ROW_INDEX, $key);
			$startCol = $myCol;
			foreach($value as $key2=>$value2)
			{
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $ROW_INDEX + 1, $value2);
				$myCol++;
			}
			$objPHPExcel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex($startCol).$ROW_INDEX.':'.PHPExcel_Cell::stringFromColumnIndex($myCol - 1).($ROW_INDEX));
		}
		$objPHPExcel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex($startCategoryCol).$startCategoryRow.':'.PHPExcel_Cell::stringFromColumnIndex($myCol - 1).($startCategoryRow));
		$objPHPExcel->getActiveSheet()
				->getStyle(PHPExcel_Cell::stringFromColumnIndex($startCategoryCol).$startCategoryRow.':'.PHPExcel_Cell::stringFromColumnIndex($myCol - 1).($startCategoryRow + 2))
				->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB ($color_ladang_tenusu)  ;
	}
	
	if($count_babi > 0)
	{
		$startCategoryCol = $myCol;
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $startCategoryRow, 'LADANG BABI');
		$ROW_INDEX = $startCategoryRow + 1;
		foreach($babiTitle as $key=>$value)
		{
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $ROW_INDEX, $key);
			$startCol = $myCol;
			foreach($value as $key2=>$value2)
			{
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $ROW_INDEX + 1, $value2);
				$myCol++;
			}
			$objPHPExcel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex($startCol).$ROW_INDEX.':'.PHPExcel_Cell::stringFromColumnIndex($myCol - 1).($ROW_INDEX));
		}
		$objPHPExcel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex($startCategoryCol).$startCategoryRow.':'.PHPExcel_Cell::stringFromColumnIndex($myCol - 1).($startCategoryRow));
		$objPHPExcel->getActiveSheet()
				->getStyle(PHPExcel_Cell::stringFromColumnIndex($startCategoryCol).$startCategoryRow.':'.PHPExcel_Cell::stringFromColumnIndex($myCol - 1).($startCategoryRow + 2))
				->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB ($color_ladang_babi)  ;
	}
	
	if($count_aneka > 0)
	{
		$startCategoryCol = $myCol;
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $startCategoryRow, 'LADANG BABI');
		$ROW_INDEX = $startCategoryRow + 1;
		foreach($anekaTitle as $key=>$value)
		{
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $ROW_INDEX, $key);
			$startCol = $myCol;
			foreach($value as $key2=>$value2)
			{
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $ROW_INDEX + 1, $value2);
				$myCol++;
			}
			$objPHPExcel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex($startCol).$ROW_INDEX.':'.PHPExcel_Cell::stringFromColumnIndex($myCol - 1).($ROW_INDEX));
		}
		$objPHPExcel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex($startCategoryCol).$startCategoryRow.':'.PHPExcel_Cell::stringFromColumnIndex($myCol - 1).($startCategoryRow));
		$objPHPExcel->getActiveSheet()
				->getStyle(PHPExcel_Cell::stringFromColumnIndex($startCategoryCol).$startCategoryRow.':'.PHPExcel_Cell::stringFromColumnIndex($myCol - 1).($startCategoryRow + 2))
				->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB ($color_ladang_aneka)  ;
	}
	
	//$END_COLUMN_ALPHABET = PHPExcel_Cell::stringFromColumnIndex($myCol - 1); //convert to alphabet
	$objPHPExcel->getActiveSheet()->getStyle($START_COLUMN_ALPHABET.($ROW_INDEX - 1).':'.$END_COLUMN_ALPHABET.($ROW_INDEX))->getFont()->setBold(true); //set header to bold
	$ROW_INDEX++;
	$ROW_INDEX++;
	
	//print table data
	for( $rowNum = 0 ; $rowNum < count($dataArray) ; $rowNum++ )
	{
		$kpbaru = $dataArray[$rowNum]['kpbaru_pemilik'];
		$year = ((substr($kpbaru, 0, 2) <= date("y"))?'20':'19').substr($kpbaru, 0, 2);
		$month = substr($kpbaru, 2, 2);
		$day = substr($kpbaru, 4, 2);
		$lastdigit = substr($kpbaru, -4);
		$tkh_lahir = $year."-".$month."-".$day;
								
		$myCol = $START_COLUMN;
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['id_ladang']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['nama_pemilik']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['nama_penternak']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['kpbaru_pemilik']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $year);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $month);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $day);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $tkh_lahir);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $lastdigit);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['desk_jantina']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, date('Y') - $year);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['desk_bangsa']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['id_bangsa'] == 1? 'BUMIPUTERA' : '/');
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['tel_pemilik']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['alamat_pemilik']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['id_premis']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['alamat_ladang']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['gps_ladang_lat'].','.$dataArray[$rowNum]['gps_ladang_long']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['desk_negeri']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['desk_daerah']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, '99');
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['desk_parlimen']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['desk_dun']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['desk_status_ladang']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['desk_projek_kerajaan']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['desk_katpemilik']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['desk_status_lesen']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['desk_sistem_pemeliharaan']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['desk_hakmilik']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['desk_kategori_tanah']);
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['desk_syarat_nyata_tanah']);
		
		//ruminan
		if($count_ruminan > 0)
		{
			$startCol = $myCol;
			if($dataArray[$rowNum]['id_ladang_ruminan'] == 0)
			{
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $rowNum + $ROW_INDEX, 'TIDAK BERKENAAN');
				$objPHPExcel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex($myCol).($rowNum + $ROW_INDEX).':'.PHPExcel_Cell::stringFromColumnIndex($myCol + $count_ruminan - 1).($rowNum + $ROW_INDEX));
				$objPHPExcel->getActiveSheet()
				->getStyle(PHPExcel_Cell::stringFromColumnIndex($startCol).($rowNum + $ROW_INDEX).':'.PHPExcel_Cell::stringFromColumnIndex($startCol + $count_ruminan - 1).($rowNum + $ROW_INDEX))
				->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB ($color_tidak_berkenaan)  ;
				$myCol += $count_ruminan;
			}
			else
			{
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_luas_kandang']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_luas_fodder']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_luas_ragutan']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_kapasiti_pedaging']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_kapasiti_fidlot']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_kapasiti_kambing']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_kapasiti_bebiri']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_kapasiti_kerbau']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_id_kategori_ladang_lembu']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_id_kategori_ladang_kambing']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_id_kategori_ladang_kerbau']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kk_baka']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kk_jurusan']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kk_j1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kk_j2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kk_j3']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kk_b1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kk_b2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kk_b3']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kacukan_baka']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kacukan_jurusan']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kacukan_j1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kacukan_j2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kacukan_j3']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kacukan_b1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kacukan_b2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_lembu_kacukan_b3']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_kerbau_baka']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_kerbau_jurusan']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_kerbau_j1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_kerbau_j2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_kerbau_j3']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_kerbau_b1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_kerbau_b2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_kerbau_b3']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_kambing_baka']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_kambing_jurusan']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_kambing_j1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_kambing_j2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_kambing_b1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_kambing_b2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_bebiri_baka']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_bebiri_jurusan']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_bebiri_j1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_bebiri_j2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_bebiri_b1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bt_bebiri_b2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bil_jual_lembu']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_nilai_jualan_lembu']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bil_jual_kerbau']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_nilai_jualan_kerbau']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bil_jual_kambing']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_nilai_jualan_kambing']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_bil_jual_bebiri']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lr_nilai_jualan_bebiri']);
				$objPHPExcel->getActiveSheet()
				->getStyle(PHPExcel_Cell::stringFromColumnIndex($startCol).($rowNum + $ROW_INDEX).':'.PHPExcel_Cell::stringFromColumnIndex($startCol + $count_ruminan - 1).($rowNum + $ROW_INDEX))
				->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB ($color_ladang_ruminan)  ;
			}
		}
		
		//ruminan
		if($count_tenusu > 0)
		{
			$startCol = $myCol;
			if($dataArray[$rowNum]['id_ladang_tenusu'] == 0)
			{
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $rowNum + $ROW_INDEX, 'TIDAK BERKENAAN');
				$objPHPExcel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex($myCol).($rowNum + $ROW_INDEX).':'.PHPExcel_Cell::stringFromColumnIndex($myCol + $count_tenusu - 1).($rowNum + $ROW_INDEX));
				$objPHPExcel->getActiveSheet()
				->getStyle(PHPExcel_Cell::stringFromColumnIndex($startCol).($rowNum + $ROW_INDEX).':'.PHPExcel_Cell::stringFromColumnIndex($startCol + $count_tenusu - 1).($rowNum + $ROW_INDEX))
				->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB ($color_tidak_berkenaan)  ;
				$myCol += $count_tenusu;
			}
			else
			{
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_luas_kandang']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_luas_fodder']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_luas_ragutan']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_kapasiti_lembu']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_kapasiti_kerbau']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_kapasiti_kambing']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_kapasiti_bebiri']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_id_kategori_ladang_tenusu']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_lembu_baka']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_lembu_j1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_lembu_j2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_lembu_j3']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_lembu_b1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_lembu_b2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_lembu_b3']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_kerbau_baka']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_kerbau_j1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_kerbau_j2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_kerbau_j3']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_kerbau_b1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_kerbau_b2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_kerbau_b3']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_kambing_baka']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_kambing_j1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_kambing_j2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_kambing_b1']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bt_kambing_b2']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_bil_jual_ternakan']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_nilai_jualan_ternakan']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_nilai_jualan_ternakan_tahunan']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_jumlah_susu_sehari_lembu']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_nilai_jualan_susu_lembu']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_nilai_jualan_susu_tahunan_lembu']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_jumlah_susu_sehari_kambing']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_nilai_jualan_susu_kambing']);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]['lt_nilai_jualan_susu_tahunan_kambing']);
				$objPHPExcel->getActiveSheet()
				->getStyle(PHPExcel_Cell::stringFromColumnIndex($startCol).($rowNum + $ROW_INDEX).':'.PHPExcel_Cell::stringFromColumnIndex($startCol + $count_tenusu - 1).($rowNum + $ROW_INDEX))
				->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB ($color_ladang_tenusu)  ;
			}
		}
		
		//babi
		if($count_babi > 0)
		{
			$startCol = $myCol;
			if($dataArray[$rowNum]['id_ladang_babi'] == 0)
			{
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $rowNum + $ROW_INDEX, 'TIDAK BERKENAAN');
				$objPHPExcel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex($myCol).($rowNum + $ROW_INDEX).':'.PHPExcel_Cell::stringFromColumnIndex($myCol + $count_babi - 1).($rowNum + $ROW_INDEX));
				$objPHPExcel->getActiveSheet()
				->getStyle(PHPExcel_Cell::stringFromColumnIndex($startCol).($rowNum + $ROW_INDEX).':'.PHPExcel_Cell::stringFromColumnIndex($startCol + $count_babi - 1).($rowNum + $ROW_INDEX))
				->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB ($color_tidak_berkenaan)  ;
				$myCol += $count_babi;
			}
			else
			{
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_luas_ladang"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_kapasiti_ladang"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_baka_babi"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_bil_kandang_tertutup"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_bil_kandang_semi_terbuka"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_bil_kandang_terbuka"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_bil_sisa_kumbahan"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["id_pengolahan_sisa_kumbahan"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_exist_zon_penampan"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_exist_gahp"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_exist_homemixer"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_jumlah_spesis_boar"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_jumlah_spesis_induk"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_jumlah_spesis_lain"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_jumlah_spesis_spp"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_bil_jualan"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_nilai_jualan"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["lb_jumlah_jualan"]);

				$objPHPExcel->getActiveSheet()
				->getStyle(PHPExcel_Cell::stringFromColumnIndex($startCol).($rowNum + $ROW_INDEX).':'.PHPExcel_Cell::stringFromColumnIndex($startCol + $count_babi - 1).($rowNum + $ROW_INDEX))
				->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB ($color_ladang_babi)  ;
			}
		}
		
		//aneka
		if($count_aneka > 0)
		{
			$startCol = $myCol;
			if($dataArray[$rowNum]['id_ladang_aneka'] == 0)
			{
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol, $rowNum + $ROW_INDEX, 'TIDAK BERKENAAN');
				$objPHPExcel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex($myCol).($rowNum + $ROW_INDEX).':'.PHPExcel_Cell::stringFromColumnIndex($myCol + $count_aneka - 1).($rowNum + $ROW_INDEX));
				$objPHPExcel->getActiveSheet()
				->getStyle(PHPExcel_Cell::stringFromColumnIndex($startCol).($rowNum + $ROW_INDEX).':'.PHPExcel_Cell::stringFromColumnIndex($startCol + $count_aneka - 1).($rowNum + $ROW_INDEX))
				->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB ($color_tidak_berkenaan)  ;
				$myCol += $count_babi;
			}
			else
			{
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bil_kandang"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_kapasiti_kandang"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_luas_pengeluaran"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_luas_ladang"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_arnab_pedaging"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_arnab_pet"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_rusa_pedaging_j"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_rusa_pedaging_b"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_rusa_rekreasi_j"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_rusa_rekreasi_b"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_kuda_pembiakan_j"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_kuda_pembiakan_b"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_kuda_rekreasi_j"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_kuda_rekreasi_g"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_kuda_rekreasi_b"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_katak"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_angsa"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_piru"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_ostrich"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_selasih"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_mutiara"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bt_parrot"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_bil_jualan"]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($myCol++, $rowNum + $ROW_INDEX, $dataArray[$rowNum]["la_nilai_jualan"]);

				$objPHPExcel->getActiveSheet()
				->getStyle(PHPExcel_Cell::stringFromColumnIndex($startCol).($rowNum + $ROW_INDEX).':'.PHPExcel_Cell::stringFromColumnIndex($startCol + $count_aneka - 1).($rowNum + $ROW_INDEX))
				->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB ($color_ladang_aneka)  ;
			}
		}
	}
	$ROW_INDEX += count($dataArray) - 1;
	$END_ROW = $ROW_INDEX; //keep a record of end row of table
	
	//set border and alignment for table
	$objPHPExcel->getActiveSheet()->getStyle($START_COLUMN_ALPHABET.$START_ROW.':'.$END_COLUMN_ALPHABET.$END_ROW)->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
	$objPHPExcel->getActiveSheet()->getStyle($START_COLUMN_ALPHABET.$START_ROW.':'.$END_COLUMN_ALPHABET.$END_ROW)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	$objPHPExcel->getActiveSheet()->getStyle($START_COLUMN_ALPHABET.$START_ROW.':'.$END_COLUMN_ALPHABET.$END_ROW)->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	$objPHPExcel->getActiveSheet()->getStyle($START_COLUMN_ALPHABET.$START_ROW.':'.$END_COLUMN_ALPHABET.$END_ROW)->getAlignment()->setWrapText(true);

	// Rename worksheet
	$objPHPExcel->getActiveSheet()->setTitle('Table Data');

	// Set active sheet index to the first sheet, so Excel opens this as the first sheet
	$objPHPExcel->setActiveSheetIndex(0);
	
	//set auto width
	for( $colNum = $START_COLUMN ; $colNum <= $END_COLUMN ; $colNum++ )
	{
		$objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($colNum))->setAutoSize(true);
	}
	
	//set auto height
	$objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(-1);
	
	//$objPHPExcel->getActiveSheet()->getColumnDimension($START_COLUMN_ALPHABET.':'.$END_COLUMN_ALPHABET)->setAutoSize(true);

	// Redirect output to a client’s web browser (Excel2007)
	header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
	header('Content-Disposition: attachment;filename="'.$FILE_NAME.'.xlsx"');
	header('Cache-Control: max-age=0');
	// If you're serving to IE 9, then the following may be needed
	header('Cache-Control: max-age=1');

	// If you're serving to IE over SSL, then the following may be needed
	header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
	header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
	header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
	header ('Pragma: public'); // HTTP/1.0

	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
	$objWriter->save('php://output');
	exit;
?>