小编Aud*_*rey的帖子

使用phpword编辑docx文件

是否可以使用 phpword 编辑现有的 docx 文件?

我想将页脚文本添加到我现有的 docx 文件中。

有很多例子,但这些例子是从头开始创建 doc 文件而不是编辑文件有人可以链接给我一个例子吗?谢谢你

像这样。

<?php
require_once 'PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->createSection();
// Add header
$header = $section->createHeader();
$table = $header->addTable();
$table->addRow();
$table->addCell(4500)->addText('This is the header.');
$table->addCell(4500)->addImage('_earth.jpg', array('width'=>50, 'height'=>50, 'align'=>'right'));
// Add footer
$footer = $section->createFooter();
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align'=>'center'));
// Write some text
$section->addTextBreak();
$section->addText('Some text...');
// Save File
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('HeaderFooter.docx');
?>
Run Code Online (Sandbox Code Playgroud)

php phpword

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

php ×1

phpword ×1