1. 安装:
    composer require phpoffice/phpword
  2. 导出:
    <?php
    // 1. 引入包
    require_once 'vendor/autoload.php';
    // 2. 使用命名空间
    use PhpOffice\PhpWord\PhpWord;
    use PhpOffice\PhpWord\IOFactory;
    // 3. 实例化 word 对象
    $phpWord = new PhpWord();
    // 4. 添加段落
    $section = $phpWord->addSection();
    // 5. 配置文本格式
    $section->addText(
     '测试文本',
     array(
         'name' => '微软雅黑',
         'size' => 10,
         'color' => '1B2232',
         'bold' => true
     )
    );
    // 6. 实例化 writer 对象
    $writer = IOFactory::createWriter($phpWord, 'Word2007');
    // 7. 保存
    $writer->save('test.docx');
文档更新时间: 2020-08-07 18:49   作者:lee