今天练习了下面的代码关于PHPexcel的(windows下的):
代码如下:
$dir = dirname(__FILE__);
require_once 'PHPExcel.php';
$phpExcel = new PHPExcel();
$objSheet = $phpExcel -> getActiveSheet();
$objSheet -> setTitle('wgq');
$objSheet -> setCellValue('A1','姓名') -> setCellValue('B1','年龄') ->setCellValue('C1', '性别');
$objSheet -> setCellValue('A2', 'eee') -> setCellValue('B2', 24) -> setCellValue('C2', '男');
$objWrite = PHPExcel_IOFactory::createWriter($phpExcel,'Excel5');
$objWrite -> save($dir, 'demo1.xls');
返回的结果如下:
Warning: fopen(D:\PHPExcel) [function.fopen]: failed to open stream: Permission denied in D:\PHPExcel\PHPExcel\Shared\OLE\PPS\Root.php on line 90
Fatal error: Uncaught exception 'PHPExcel_Writer_Exception' with message 'Can't open D:\PHPExcel. It may be in use or protected.' in D:\PHPExcel\PHPExcel\Shared\OLE\PPS\Root.php:93 Stack trace: #0 D:\PHPExcel\PHPExcel\Writer\Excel5.php(226): PHPExcel_Shared_OLE_PPS_Root->save('D:\PHPExcel') #1 D:\PHPExcel\demo.php(10): PHPExcel_Writer_Excel5->save('D:\PHPExcel', 'demo1.xls') #2 {main} thrown in D:\PHPExcel\PHPExcel\Shared\OLE\PPS\Root.php on line 93
请问这是什么问题,这是在windows下的操作的,我看的那个视频老师好像也是windows的直接就好用了,
权限不足导致的吧
最后一行改为:
$objWrite->save($dir, 'demo1.xls');
=》
$objWrite->save('php://output');
这是 直接输出