hamichen/opentbs-bundle

OpenTBS Bundle for ZF2 - 使用 ZF2 创建 OpenOffice 和 Ms Office 文档

dev-master 2016-08-27 07:18 UTC

This package is not auto-updated.

Last update: 2024-09-09 14:04:15 UTC


README

此扩展包仅是使用 OpenTBS 的便捷方式,所有荣誉归功于 https://github.com/mbence、Skrol29 和 TinyButStrong 团队。http://www.tinybutstrong.com/

OpenTBS - 使用 PHP (及 ZF2) 创建 OpenOffice 和 Ms Office 文档

简介

(摘自 http://www.tinybutstrong.com/plugins/opentbs/tbs_plugin_opentbs.html)

OpenTBS 是一个 PHP 工具,使用模板生成任何 OpenOffice 和 Ms Office 文档。

OpenTBS 可以合并任何 OpenDocument 和 Open XML 文件。它自动识别扩展名:odt、ods、odg、odf、odm、odp、ott、ots、otg、otp、docx、xlsx、pptx。实际上,它可以合并任何存储在 zip 容器中的 XML 或文本文件(这是 OpenDocuments 和 OpenXML 文档的情况)。

OpenTBS 的特点

  • 直接使用 OpenOffice 或 MS Office 设计模板。
  • 合并文档不需要 exe 文件。
  • 合并文档不需要临时文件。
  • 直接以 http 下载、磁盘上的新文件或字符串(例如文件附件)输出。
  • 与 PHP 4 和 PHP 5 都兼容。

包含的版本

TinyButStrong - 3.9.0

OpenTBS - 1.9.4

要求

安装

步骤 1: 使用 composer 下载扩展包

在您的 composer.json 中添加以下内容

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/kipperlenny/opentbsbundle"
        }
    ],
    "require": {
        "hamichen/opentbs-bundle": "dev-master"
    }
}

然后运行以下命令下载/更新

$ php composer.phar update hamichen/opentbs-bundle

Composer 将将扩展包安装到您的项目的 vendor/Kipperlenny/opentbs-bundle 目录。

步骤 2: 在您的 application.config.php 中添加扩展包

'OpentbsBundle',

现在您可以使用 'opentbs' 服务。

使用 OpenTBSBundle

首先您需要在您的 docx 模板中定义变量(您可以使用任何其他支持的文档格式)。

... some text in a word file with a `[client.name]` variable ...

In TBS 您总是需要一个变量基础 client 和一个变量名 name

然后在您的控制器中,您需要获取 OpenTBS 服务,加载您的模板并合并字段(例如替换模板变量)。

...
use OpentbsBundle\Factory\TBSFactory as TBS;
...

    $tbs = new TBS();
    $tbs->LoadTemplate('document.odt');

关于 onshow 自动变量的说明:您可以在 onshow 基础中定义您的变量(例如 onshow.name),但我不建议这样做,因为它只会在您使用全局变量时工作。

更多信息...

请参阅 http://www.tinybutstrong.com/manual.php 中的 TBS 手册

以及 OpenTBS 插件文档 http://www.tinybutstrong.com/plugins/opentbs/tbs_plugin_opentbs.html