PHPExcel将PHP变量传递到电子表格属性
尝试将该变量设置为函数中的全局变量PHPExcel将PHP变量传递到电子表格属性,php,phpexcel,Php,Phpexcel,尝试将该变量设置为函数中的全局变量 <?php //Initialize variables for downloads $report_name = $_POST['herd-reports-download-name']; $filetype = $_POST['group1']; $farm_id = $_POST['farm_id']; $username = $_POST['user_name']; $json_array = json_decode($_
<?php
//Initialize variables for downloads
$report_name = $_POST['herd-reports-download-name'];
$filetype = $_POST['group1'];
$farm_id = $_POST['farm_id'];
$username = $_POST['user_name'];
$json_array = json_decode($_POST['table_data'], true);
$wksDescription = "Report generated for farm";
//Branch casing depending on filetype
switch($filetype) {
case 'PDF':
generate_pdf();
break;
case 'Excel':
generate_excel();
break;
}
//Functions for downloads here.
function generate_pdf() {
//echo 'pdf';
}
function generate_excel() {
//echo 'excel';
require '../includes/libraries/PHPExcel/Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel(); //Spreadsheet generated, one worksheet is always added to it.
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory_serialized;
PHPExcel_Settings::setCacheStorageMethod($cacheMethod); //Serializes to cut memory usage slightly at a minor performance hit.
$objPHPExcel->getProperties()->setCreator("myself")
->setLastModifiedBy("myself")
->setTitle("Report for a farm")
->setSubject("A report")
->setDescription($wksDescription)
->setKeywords("office 2007 etc")
->setCategory("Report File");
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Snoop Dawg');
//Once it's done, begin prep to output to browser
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename=vroom");
header('Cache-Control: max-age=1');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
}
?>
该变量不存在于函数的范围内,除非从外部将其拉入。我不敢相信我错过了它。
function generate_excel() {
global $wksDescription;