dpa55065 2016-02-01 17:14
浏览 139
已采纳

Phpword $ objWriter属性

I am using PHPWord in a project.

I am trying to find out some information about the attributes that go with the $objWriter:

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');

Specifically, what is the 'Word2007' used for at the end? I have tried searching $objWriter but can't locate any info. I have tried replacing it with 'Word2013' or 'Word2016' but I get:

"Word2016" is not a valid writer. in wamp...\vendor\phpoffice\phpword\src\PhpWord\IOFactory.php on line 29

  • 写回答

1条回答 默认 最新

  • dpdyh86002 2016-02-01 17:17
    关注

    The 2nd parameter is for the type of document you're creating a writer for. There are 5 allowed types:

    1. 'ODText'
    2. 'RTF'
    3. 'Word2007'
    4. 'HTML'
    5. 'PDF'

    You can see this in the code for the IOFactory class:

    public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
    {
        /**
         * Notice the allowed names in the array here.
         */
        if ($name !== 'WriterInterface' && !in_array($name, array('ODText', 'RTF', 'Word2007', 'HTML', 'PDF'), true)) {
            throw new Exception("\"{$name}\" is not a valid writer.");
        }
        $fqName = "PhpOffice\\PhpWord\\Writer\\{$name}";
        return new $fqName($phpWord);
    }
    

    https://github.com/PHPOffice/PHPWord/blob/develop/src/PhpWord/IOFactory.php

    If you want to support a later MS Word document format, you will need to implement your own writer that extends AbstractWriter implements WriterInterface. However, at this time, there are no later formats yet created. (Note that Word 2007 the format is different from the application version.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题