无法为使用PhpExcel生成的.xlsm文件启用内容

时间:2019-06-17 10:33:35

标签: excel vba phpspreadsheet xlsm phpexcel-1.8.0

我正在尝试在现有的.xlsm模板上加载和写入内容,并将其另存为其他目录中的新文件。这些文件具有宏,需要像在原始文件中一样保护这些宏。我已经在php中完成以下操作以获得结果:

 <?php

    error_reporting(E_ALL);
    ini_set('display_errors', TRUE);
    ini_set('display_startup_errors', TRUE);

    require_once dirname(__FILE__) . '/php_excel/Classes/PHPExcel.php';
    require_once dirname(__FILE__) . '/php_excel/Classes/PHPExcel/IOFactory.php';
    require_once dirname(__FILE__) . '/php_excel/Classes/PHPExcel/Reader/IReadFilter.php';
    date_default_timezone_set('Europe/London');

    $sheets = array('Welcome', 'Instructions', 'Data Definitions', 'Clothing');

    $inputFileName = __DIR__ . '/templates/Clothing.xlsm';

    $inputFileType = PHPExcel_IOFactory::identify($inputFileName);

    $this->PHPExcelReader = PHPExcel_IOFactory::createReader($inputFileType);
    $sheetnames = $sheets;
    $this->PHPExcelReader->setLoadSheetsOnly($sheetnames);
    $this->PHPExcel = $this->PHPExcelReader->load($inputFileName);


    $this->PHPExcel->setActiveSheetIndex(3);

    // Redirect output to a client’s web browser (Excel2007)
    ob_end_clean();
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="test.xlsm"');
    header('Cache-Control: max-age=0');

    $objWriter = PHPExcel_IOFactory::createWriter($this->PHPExcel, 'Excel2007');
    ob_end_clean();
    $objWriter->save($this->filename);

    $this->PHPExcel->disconnectWorksheets();
    unset($this->PHPExcel);

$ this->文件名在我的课程中可用。

一切正常。我得到的内容与原始文件完全相同,但是在启用内容的同时我得到了

  

运行时错误“ 9”:   下标超出范围。

Cloned File | Original File

我在github和wiki上看到了很多帖子,但没有找到我需要的东西。 This was some how close,但没有答案,或者只是说phpexcel不支持xlsm文件。如果是这样,什么是支持xlsm和macros的最佳库?自3天以来,我一直坚持下去。 任何建议和帮助都非常感谢。
谢谢。

0 个答案:

没有答案