código

código

<? Php
ini_set ('display_errors', 1);
require_once ('PHPExcel.php');
require_once ('PHPExcel / IOFactory.php');
include_once ('../../../ wp-load.php');
$ objPHPExcel = nuevo PHPExcel ();
Global $ wpdb;
// $ objPHPExcel-> getActiveSheet ();

$ objPHPExcel-> setActiveSheetIndex (0) -> setCellValue ('A1', 'Informes de donaciones');
$ objPHPExcel-> setActiveSheetIndex (0) -> mergeCells ('A1: C1', ");
$ objPHPExcel-> setActiveSheetIndex (0) -> setCellValue ('A2', 'SI');
$ objPHPExcel-> setActiveSheetIndex (0) -> setCellValue ('B2', 'Proyecto');
$ objPHPExcel-> setActiveSheetIndex (0) -> setCellValue ('C2', 'Sub Project');
$ objPHPExcel-> setActiveSheetIndex (0) -> setCellValue ('D2', 'Ubicación');
$ objPHPExcel-> setActiveSheetIndex (0) -> setCellValue ('E2', 'Total');

$ file = 'Donación'. hora() . '.xlsx'; //
// $ objWriter = PHPExcel_IOFactory :: createWriter ($ objPHPExcel, 'Excel2007');
// $ objWriter-> save ("upload / excelsheet /". $ file);
// Cambiar nombre hoja de cálculo
$ objPHPExcel-> getActiveSheet () -> setTitle ('Matriz de precios');

// Establece el índice de la hoja activa en la primera hoja, por lo que Excel lo abre como la primera hoja
$ objPHPExcel-> setActiveSheetIndex (0);

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

$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 ['proyecto']);
$ objPHPExcel-> getActiveSheet () -> SetCellValue ('C'. $ i, $ row ['sub_project']);
$ objPHPExcel-> getActiveSheet () -> SetCellValue ('D'. $ i, $ row ['location']);
$ objPHPExcel-> getActiveSheet () -> SetCellValue ('E'. $ i, '£' .number_format ($ row ['totalamount'], 2));

$ I ++;
$ j ++;
}

$ objWriter = PHPExcel_IOFactory :: createWriter ($ objPHPExcel, 'Excel2007');
$ objWriter-> save ("upload / excelsheet /". $ archivo);
$ file_url = 'archivo upload / excelsheet /'.$;

encabezado ('Content-Type: application / vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header ("Content-Disposition: attachment; filename =". $ file);
header ("Cache-Control: debe-revalidar, post-check = 0, pre-check = 0");
ob_end_clean ();
readfile ($ file_url);
Salida;

>

¿NECESITA AYUDA? Haga clic aquí para obtener ayuda en línea