热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在YII里面使用PHPExcelexternallibrary

为什么80%的码农都做不了架构师?首先修改PHPEXCELAutoloader.php的文件publicstaticfunctionLoad($pObjectN

为什么80%的码农都做不了架构师?>>>   hot3.png

首先修改PHPEXCEL /Autoloader.php的文件

public static function Load($pObjectName){ if ((class_exists($pObjectName)) || (strpos($pObjectName, 'PHPExcel') === False)) { return false;} // this is the code that shows what I am saying $pObjectFilePath = PHPEXCEL_ROOT.str_replace('_',DIRECTORY_SEPARATOR,$pObjectName).'.php';if ((file_exists($pObjectFilePath) === false) || (is_readable($pObjectFilePath) === false)) { return false;} require($pObjectFilePath);

} // function Load()

然后

class TestController extends Controller{ // no layouts here public $layout = '';public function actionTest() { // // get a reference to the path of PHPExcel classes $phpExcelPath = Yii::getPathOfAlias('ext.phpexcel.Classes');// Turn off our amazing library autoload spl_autoload_unregister(array('YiiBase','autoload')); // // making use of our reference, include the main class // when we do this, phpExcel has its own autoload registration // procedure (PHPExcel_Autoloader::Register();) include($phpExcelPath . DIRECTORY_SEPARATOR . 'PHPExcel.php');// Create new PHPExcel object $objPHPExcel = new PHPExcel();// Set properties $objPHPExcel->getProperties()->setCreator("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw") ->setTitle("PDF Test Document") ->setSubject("PDF Test Document") ->setDescription("Test document for PDF, generated using PHP classes.") ->setKeywords("pdf php") ->setCategory("Test result file");// Add some data $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', 'Hello') ->setCellValue('B2', 'world!') ->setCellValue('C1', 'Hello') ->setCellValue('D2', 'world!');// Miscellaneous glyphs, UTF-8 $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A4', 'Miscellaneous glyphs') ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');// Rename sheet $objPHPExcel->getActiveSheet()->setTitle('Simple');// Set active sheet index to the first sheet, // so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0);// Redirect output to a client’s web browser (Excel2007) header('Content-Type: application/pdf');header('Content-Disposition: attachment;filename="01simple.pdf"');header('Cache-Control: max-age=0');$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');$objWriter->save('php://output');Yii::app()->end();// // Once we have finished using the library, give back the // power to Yii... spl_autoload_register(array('YiiBase','autoload'));} }


转:https://my.oschina.net/qeecoo/blog/68148



推荐阅读
author-avatar
昂-恩意_180
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有