phpexcel 1.8版不允许加载.xlsm文件并保存

时间:2014-07-15 11:44:13

标签: php phpexcel

当我加载.xlsx或.xls文件时,它可以正常工作。请参阅以下代码 //加载我们的新PHPExcel库         $这 - >负载>库('的excel&#39);

    $file = "files/test.xlsx";

    $excel2 = PHPExcel_IOFactory::createReader('Excel2007');
    $excel2 = $excel2->load($file); // Empty Sheet
    //print_r($excel2); 

    $excel2->setActiveSheetIndex(1);
    $excel2->getActiveSheet()->setCellValue('C6', '4');
    $excel2->getActiveSheet()->setCellValue('A1', '5');
    $excel2->getActiveSheet()->setCellValue('A2', '3');

    $excel2->setActiveSheetIndex(2);
    $excel2->getActiveSheet()->setCellValue('A7', '4');

    $filename='Registration_Report.xlsx';
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //mime type
    header('Content-Disposition: attachment;filename="'.$filename.'"');  //tell browser what's the file name
    header('Cache-Control: max-age=0'); //no cache

    $objWriter = PHPExcel_IOFactory::createWriter($excel2, 'Excel2007');
    $objWriter->save('php://output');

但是当我加载宏文件,即.xlsm时,没有任何反应。请参阅以下代码

//加载我们的新PHPExcel库         $这 - >负载>库('的excel&#39);

    $file = "files/test.xlsm";

    $excel2 = PHPExcel_IOFactory::createReader('Excel2007');
    $excel2 = $excel2->load($file); // Empty Sheet
    //print_r($excel2); 

    $excel2->setActiveSheetIndex(1);
    $excel2->getActiveSheet()->setCellValue('C6', '4');
    $excel2->getActiveSheet()->setCellValue('A1', '5');
    $excel2->getActiveSheet()->setCellValue('A2', '3');

    $excel2->setActiveSheetIndex(2);
    $excel2->getActiveSheet()->setCellValue('A7', '4');

    $filename='Registration_Report.xlsm';
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //mime type
    header('Content-Disposition: attachment;filename="'.$filename.'"');  //tell browser what's the file name
    header('Cache-Control: max-age=0'); //no cache

    $objWriter = PHPExcel_IOFactory::createWriter($excel2, 'Excel2007');
    $objWriter->save('php://output');

我使用的是最新版本的phpExcel,即1.8,该类确实包含了hasMacro函数......

0 个答案:

没有答案