molbio-unige/php-word-view 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

molbio-unige/php-word-view

最新稳定版本:1.1.1

Composer 安装命令:

composer require molbio-unige/php-word-view

包简介

PhpWordView plugin for CakePHP

README 文档

README

This plugin renders Word documents using the PhpWord library. This plugin uses the TemplateProcessor of PhpWord.

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require molbio-unige/php-word-view

Enable plugin

Load the plugin by running command

bin/cake plugin load PhpWordView

Usage

Two different ways to render.

PHPWord TemplateProcessor

To be used if you need to render simple documents. Serialize the data you want to insert into the template.

The templates are expected to be present in src/Templates/Model/docx/, and having .docx filename extension. Template files are just plain word document, not Word model documents.

Create a template document

public function imprimatur()
{
    $imprimatur = '667';
    $this->viewBuilder()
         ->setClassName('PhpWordView.PhpWord');
         
    $data = [
        'title' => 'Beati Pauperes Spiritu,
        'imprimatur' => $imprimatur,
    ];
    $_serialize = 'data';
    $this->set(compact('data', '_serialize'));
}

PHPWord full api

To be used when a simple search-replace is not sufficient.

The view files are expected to be present in src/Templates/Model/docx/, but having .ctp filename extension. Inside your view files you will have access to the PHPWord library with $this->PhpWord. Check the PHPWord documentation on how to use PHPWord.

Don't set the _serialize variable.

public function imprimatur($id)
{
    $this->viewBuilder()
         ->setClassName('PhpWordView.PhpWord');
    $imprimatur = $this->Imprimaturs->get($id);
    $this->set(compact('imprimatur'));
}

Downloaded filename

The downloaded filename can be specified with the viewBuilder options, default is the action name.

    $this->viewBuilder()
         ->setClassName('PhpWordView.PhpWord')
         ->options([
             'wordConfig' => [
                 'filename' => 'imprimatur-' . $id,
             ]
         ]);

Troubleshooting

A Could not close zip file /tmp/PhpWord5gJC0Z Exception might mean that there is a problem with the template.docx file have incorrect line ending. This can be solved by specifying docx files as binary in the .gitattributes file.

统计信息

  • 总下载量: 21
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固