export excel xlsx file corrupt

 <?php
include ('../../../inc/includes.php');
include (GLPI_ROOT."/plugins/oci/PHPExcel/PHPExcel.php");

global $DB;

$excel = new PHPExcel();

// Settingan awal file excel
$excel->getProperties()	->setCreator('Test')
						->setLastModifiedBy('Test')
						->setTitle("Report")
						->setSubject("Report")
						->setDescription("Report")
						->setKeywords("Report");

$style_col = array(
  'font' => array('bold' => true),
  'alignment' => array(
  	'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  	'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER
  ),
  'borders' => array(
  'top' => array(
  	'style'  => PHPExcel_Style_Border::BORDER_THIN),
  	'right' => array(
  		'style'  => PHPExcel_Style_Border::BORDER_THIN),
  		'bottom' => array(
  		'style'  => PHPExcel_Style_Border::BORDER_THIN),
  		'left' => array(
  			'style'  => PHPExcel_Style_Border::BORDER_THIN)
  	)
);

$style_row = array(
	'alignment' => array(
	'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER),
	'borders' => array(
		'top' => array('style'  => PHPExcel_Style_Border::BORDER_THIN),
		'right' => array('style'  => PHPExcel_Style_Border::BORDER_THIN),
		'bottom' => array('style'  => PHPExcel_Style_Border::BORDER_THIN),
		'left' => array('style'  => PHPExcel_Style_Border::BORDER_THIN)
	)
);

$excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(TRUE);
$excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(15);
$excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

$excel->setActiveSheetIndex(0)->setCellValue('A2', "Host");
$excel->setActiveSheetIndex(0)->setCellValue('B2', "Host Switch");
$excel->setActiveSheetIndex(0)->setCellValue('C2', "Host Switch Port");

$excel->getActiveSheet()->getStyle('A2')->applyFromArray($style_col);
$excel->getActiveSheet()->getStyle('B2')->applyFromArray($style_col);
$excel->getActiveSheet()->getStyle('C2')->applyFromArray($style_col);

$query = "SELECT * FROM glpi_temp_physics where id = 55151";
$data = $DB->query($query);
$numrow = 3;
foreach ($data as $key => $value) {
	$datahost = $value['host'];
	$datahostswitch = $value['host_switch'];
	$datahostswitchport = $value['host_switch_port'];

	$excel->setActiveSheetIndex(0)->setCellValue('A'.$numrow, $value['host']);
	$excel->setActiveSheetIndex(0)->setCellValue('B'.$numrow, $value['host_switch']);
	$excel->setActiveSheetIndex(0)->setCellValue('C'.$numrow, $value['host_switch_port']);

	$numrow++;
}

$excel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);// Set judul file excel nya
$excel->getActiveSheet(0)->setTitle("Report");
$excel->setActiveSheetIndex(0);// Proses file excel
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Disposition: attachment; filename=nama_filenya.xls");
header('Cache-Control: max-age=0');
$write = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$write->save('php://output');
avatar Renaldy27
@Renaldy27

47 Kontribusi 2 Poin

Diperbarui 6 tahun yang lalu

1 Jawaban:

tolong gan, dijelasin agan dapet error dimana. atau gak minimal ada kalimat bertanyanya gan..

jangan cuma code doang di copy paste, kita mau bantu juga bingung permasalahannya dimana

avatar uzzielpelawak
@uzzielpelawak

72 Kontribusi 21 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban