【发布时间】:2015-08-24 01:43:09
【问题描述】:
我正在使用 PHPWord 创建文档。我需要做的是编辑现有 docx/odt 文档的页眉/页脚内容。将内容添加到文档中并不难。但是我花了一整天的时间在互联网上寻找解决方案。这是我只能通过它向现有页眉/页脚内容添加内容的代码:
$source = "DumpFiles/".$_FILES['file']['name'];
$fileName = $_FILES['file']['name'];
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
echo "File Loaded";
// Get Sections from the imported document...
$sections = $phpWord->getSections();
$section = $sections[0];
// Adding Header and Footer Content
if(isset($_POST['headerContent']) && $_POST['headerContent']!=null)
{
$headert = $section->createHeader();
$table = $headert->addTable();
$table->addRow();
$table->addCell(4500)->addText($_POST['headerContent']);
}
if(isset($_POST['footerContent']) && $_POST['footerContent'])
{
$footervar = $section->createFooter();
$table = $footervar->addTable();
$table->addRow();
$table->addCell(4500)->addText($_POST['footerContent']);
}
我知道直接使用global 变量是一种不好的做法。 :-p
一旦我让现有代码工作,我会纠正我的代码中的这些差异。
非常感谢带有示例的解决方案。
【问题讨论】: