teqneers/phpword

PHPWord是一个用PHP编写的库,用于创建Word文档。

dev-master 2018-02-09 11:05 UTC

This package is auto-updated.

Last update: 2024-09-08 06:56:58 UTC


README

此存储库是PHPWord的源代码,已转换为Composer包。此存储库是从ferdynator分叉的。

安装

您只需获取Composer,并将以下行添加到您的composer.json

    "require": {
       "teqneers/phpword": "*"
    }

示例

表格中无法分割

如果内容无法适应页面,则防止表格行分割。整个行将移动到新页面。请参阅http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.cantsplit(v=office.14).aspx

...
$wordTable = $section->addTable('tableStyle');
$wordTable->setCantSplit(true);
...

使用制表位

<?php
require_once '../PHPWord.php';

// New Word Document
$PHPWord = new PHPWord();

$PHPWord->addParagraphStyle('multipleTab', array(
    'tabs' => array(
        new PHPWord_Style_Tab("left", 1550),
        new PHPWord_Style_Tab("center", 3200),
        new PHPWord_Style_Tab("right", 5300)
    )
));

$PHPWord->addParagraphStyle('rightTab', array(
    'tabs' => array(
        new PHPWord_Style_Tab("right", 9090)
    )
));

$PHPWord->addParagraphStyle('centerTab', array(
    'tabs' => array(
        new PHPWord_Style_Tab("center", 4680)
    )
));

// New portrait section
$section = $PHPWord->createSection();

// Add listitem elements
$section->addText("Multiple Tabs:\tOne\tTwo\tThree", NULL, 'multipleTab');
$section->addText("Left Aligned\tRight Aligned", NULL, 'rightTab');
$section->addText("\tCenter Aligned",            NULL, 'centerTab');

// Save File
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('TabStops.docx');
?>