code

code

ini_set(XCHARXdisplay_errorsXCHARX, 1);
require_once(‘PHPExcel.php’);
require_once(‘PHPExcel/IOFactory.php’);
include_once(‘../../../wp-load.php’);
$objPHPExcel = new PHPExcel();
global $wpdb;
//$objPHPExcel->getActiveSheet();

$objPHPExcel->setActiveSheetIndex(0)->setCellValue(XCHARXA1XCHARX, XCHARXDonation ReportsXCHARX);
$objPHPExcel->setActiveSheetIndex(0)->mergeCells(XCHARXA1:C1XCHARX ,XCHARX);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue(XCHARXA2XCHARX, XCHARXSIXCHARX);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue(XCHARXB2XCHARX, XCHARXProjectXCHARX);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue(XCHARXC2XCHARX, XCHARXSub ProjectXCHARX);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue(XCHARXD2XCHARX, XCHARXLocationXCHARX);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue(XCHARXE2XCHARX, XCHARXTotalXCHARX);

$file = ‘Donation’ . time() . ‘.xlsx’;//
//$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, XCHARXExcel2007XCHARX);
//$objWriter->save(“upload/excelsheet/” . $file);
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle(‘Price Matrix’);

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

$startdate = $_REQUEST['exportstartdate'].XCHARX 00:00:00XCHARX;
$enddate = $_REQUEST['exportenddate'].XCHARX 00:00:00XCHARX;

$queryexport = (“SELECT “.$wpdb->prefix.”user_donating.*,”.$wpdb->prefix.”selections.*,sum(“.$wpdb->prefix.”user_donating.total_amt) as totalamount  FROM “.$wpdb->prefix.”user_donating LEFT JOIN  “.$wpdb->prefix.”selections ON “.$wpdb->prefix.”user_donating.selection_id = “.$wpdb->prefix.”selections.uniqetime_id WHERE posted_date between ‘”.$startdate.”‘ AND ‘”.$enddate.”‘ GROUP by project, sub_project, location  “);

$result = mysql_query($queryexport);
$header = ”;
$i =3;
$j =1;

while($row = mysql_fetch_array($result)){
$objPHPExcel->getActiveSheet()->SetCellValue(‘A’.$i, $j);
$objPHPExcel->getActiveSheet()->SetCellValue(‘B’.$i, $row['project']);
$objPHPExcel->getActiveSheet()->SetCellValue(‘C’.$i, $row['sub_project']);
$objPHPExcel->getActiveSheet()->SetCellValue(‘D’.$i, $row['location']);
$objPHPExcel->getActiveSheet()->SetCellValue(XCHARXEXCHARX.$i, XCHARX£XCHARX.number_format($row['totalamount'], 2));

$ I ++;
$j++;
}

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, XCHARXExcel2007XCHARX);
$objWriter->save(“upload/excelsheet/” . $file);
$file_url = ‘upload/excelsheet/’.$file;

header(‘Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’);
header(“Content-Disposition: attachment; filename=” . $file);
header(XCHARXCache-Control: must-revalidate, post-check=0, pre-check=0XCHARX);
ob_end_clean();
readfile($file_url);
exit;

?>

HULP NODIG? Klik hier voor de online help