export excel dengan php class

ant · Jan 10, 2013
selamat siang mas ellyx, saya mau tanya tentang export excel dengan php class? saya coba di localhost jalan mas? tetapi kenapa saat di upload ke hosting dan saat di export kok gak terbaca oleh excel hasil exportnya ya mas?
mohon bantuanya mas,
Terimakasih...
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Jan 10, 2013 · 0 Suka · 0 Tidak Suka
mungkin karena ada perbedaan configurasi dari php, kamu pake class apa? PHPExcel?
0
Loading...
ant · Jan 10, 2013 · 0 Suka · 0 Tidak Suka
Iya Mas Ellyx saya pake php excel?? yang saya rubah cuma config untuk koneksi ke database mas? mohon bantuanya?
terimakasih...

NB: Ini codingnya mas:
<?php


/** Error reporting */
error_reporting(E_ALL);

/** Include PHPExcel */
require_once '../../Classes/PHPExcel.php';
include '../../Classes/PHPExcel/Writer/Excel2007.php';

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

// Set document properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
 ->setLastModifiedBy("Lamipro")
 ->setTitle("Grasindo")
 ->setSubject("List Product")
 ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
 ->setKeywords("office 2007 openxml php")
 ->setCategory("Test result file");

// Create the worksheet
$objPHPExcel->setActiveSheetIndex(0);

$objPHPExcel->getActiveSheet()->setCellValue('A7', "No")
 ->setCellValue('B7', "Code")
 ->setCellValue('C7', "Design")
 ->setCellValue('D7', "Sub Category")
 ->setCellValue('E7', "Description")
 ->setCellValue('F7', "Finish")
 ->setCellValue('G7', "Stock")
 ->setCellValue('H7', "Reserved")
  ->setCellValue('I7', "Reserved By")
  ->setCellValue('J7', "Damaged");
 
include"../config.php";
$cat=$_REQUEST['cat'];
$area=$_REQUEST['area'];

if($area=="Jakarta"){
$SQL = mysql_query("SELECT * from product where name_category='$cat'");
$totJML = mysql_num_rows($SQL);
$dataArray= array();
$no=0;
while($row = mysql_fetch_array($SQL, MYSQL_ASSOC)){
 $no++;
		 $row_array['no'] = $no;
		 $row_array['product_code'] = $row['product_code'];
		 $row_array['design'] = $row['design'];
		 $row_array['sub_category'] = $row['sub_category'];
		 $row_array['description'] = $row['description'];
		 $row_array['finish'] = $row['finish'];
		 $row_array['stock_jakarta'] = $row['stock_jakarta'];
		 $row_array['reserved'] = $row['reserved'];
		 $row_array['reservedby'] = $row['reservedby'];
		 $row_array['damaged'] = $row['damaged'];
 array_push($dataArray,$row_array);
}
$nox=$no+7;
}else{
$SQL = mysql_query("SELECT * from product where name_category='$cat'");
$totJML = mysql_num_rows($SQL);
$dataArray= array();
$no=0;
while($row = mysql_fetch_array($SQL, MYSQL_ASSOC)){
 $no++;
		 $row_array['no'] = $no;
		 $row_array['product_code'] = $row['product_code'];
		 $row_array['design'] = $row['design'];
		 $row_array['sub_category'] = $row['sub_category'];
		 $row_array['description'] = $row['description'];
		 $row_array['finish'] = $row['finish'];
		 $row_array['stock_surabaya'] = $row['stock_surabaya'];
		 $row_array['reserved2'] = $row['reserved2'];
		 $row_array['reservedby2'] = $row['reservedby2'];
		 $row_array['damaged2'] = $row['damaged2'];
 array_push($dataArray,$row_array);
}
$nox=$no+7;	
	
}
$objPHPExcel->getActiveSheet()->fromArray($dataArray, NULL, 'A8');

// Set page orientation and size
$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
$objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_LEGAL);
$objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.75);
$objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0.75);
$objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.75);
$objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.75);
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() . '&RPage &P of &N');

// Set title row bold;
$objPHPExcel->getActiveSheet()->getStyle('A7:J7')->getFont()->setBold(true);
// Set fills
$objPHPExcel->getActiveSheet()->getStyle('A7:J7')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('A7:J7')->getFill()->getStartColor()->setARGB('FF808080');

$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setAutoSize(true);
// Set autofilter
 // Always include the complete filter range!
 // Excel does support setting only the caption
 // row, but that's not a best practise...
$objPHPExcel->getActiveSheet()->setAutoFilter($objPHPExcel->getActiveSheet()->calculateWorksheetDimension());

 
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);

$sharedStyle1 = new PHPExcel_Style();
$sharedStyle2 = new PHPExcel_Style();

$sharedStyle1->applyFromArray(
 array('borders' => array(
 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
 'top' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
 'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM),
 'left' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
 ),
 ));

$objPHPExcel->getActiveSheet()->setSharedStyle($sharedStyle1, "A7:J$nox");

// Set style for header row using alternative method
$objPHPExcel->getActiveSheet()->getStyle('A7:J7')->applyFromArray(
 array(
 'font' => array(
 'bold' => true
 ),
 'alignment' => array(
 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
 ),
 'borders' => array(
 'top' => array(
 'style' => PHPExcel_Style_Border::BORDER_THIN
 )
 ),
 'fill' => array(
 'type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
 'rotation' => 90,
 'startcolor' => array(
 'argb' => 'FFA0A0A0'
 ),
 'endcolor' => array(
 'argb' => 'FFFFFFFF'
 )
 )
 )
);


$objPHPExcel->getActiveSheet()->getStyle('A7:J1000')->getFont()->setName('Arial');
$objPHPExcel->getActiveSheet()->getStyle('A7:J1000')->getFont()->setSize(10);

// Merge cells
$objPHPExcel->getActiveSheet()->mergeCells('C2:E2');
$objPHPExcel->getActiveSheet()->setCellValue('C2', "GRASINDO");
$objPHPExcel->getActiveSheet()->mergeCells('C3:E3');
$objPHPExcel->getActiveSheet()->setCellValue('C3', "DATA PRODUCT");
$objPHPExcel->getActiveSheet()->mergeCells('C4:E4');
$objPHPExcel->getActiveSheet()->setCellValue('C4', " $cat - $area");
$objPHPExcel->getActiveSheet()->mergeCells('C5:E5');
$objPHPExcel->getActiveSheet()->setCellValue('C5', "Grand Slipi Tower Lt.9 Jakarta Indonesia");
$objPHPExcel->getActiveSheet()->getStyle('C2:E6')->getFont()->setName('Arial');
$objPHPExcel->getActiveSheet()->getStyle('C2:E5')->getFont()->setSize(10);
$objPHPExcel->getActiveSheet()->getStyle('C6')->getFont()->setSize(12);
$objPHPExcel->getActiveSheet()->getStyle('C2:E6')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('A2:E6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

// Redirect output to a client’s web browser (Excel2007)
$today=date('Y-m-d');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Product_'.$today.'.xlsx"');
header('Cache-Control: max-age=0');

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

// Save Excel 2007 file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));

0
Loading...
Ellyx Christian · Jan 10, 2013 · 0 Suka · 0 Tidak Suka
sepertinya tidak ada yang salah dari kodenya, coba lihat di error_lognya apa yang salah.
0
Loading...
ant · Jan 11, 2013 · 0 Suka · 0 Tidak Suka
Pagi mas Ellyx,
Kebenyakan error lognya kaya gini mas?
[10-Jan-2013 16:13:07 Asia/Jakarta] PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening '../config.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/lamiprow/public_html/mis/mis/stockExport/select.php on line 77

sama ini mas:
[11-Jan-2013 08:47:42 Asia/Jakarta] PHP Fatal error: Class 'ZipArchive' not found in /home/lamiprow/public_html/mis/Classes/PHPExcel/Writer/Excel2007.php on line 234
[11-Jan-2013 08:53:54 Asia/Jakarta] PHP Fatal error: Class 'ZipArchive' not found in /home/lamiprow/public_html/mis/Classes/PHPExcel/Writer/Excel2007.php on line 234
Mohon bantuanya...Terimakasih
0
Loading...
Ellyx Christian · Jan 11, 2013 · 0 Suka · 0 Tidak Suka
pertama pastikan kamu menginclude dengan benar file config.php
kedua pastikan apakah extension zlib dan zip sudah dienable/diinstall di server