标签: phpword

使用TemplateProcessor在PHP.Word中添加图像

我不知道是否可以使用TemplateProcessor在PHPWord模板中添加图像.

我有一个文件(form.docx).该文档是一个模板.我阅读了字段(例如$ {name})并将其替换为文本.

$template = new TemplateProcessor('form.docx');
$template->setValue('name', $name);
Run Code Online (Sandbox Code Playgroud)

但现在,我想放一张图片,但我不知道我是怎么做的.我尝试这个:

$img='img.jpg';
$template->setValue('image',$img);
Run Code Online (Sandbox Code Playgroud)

不起作用.我尝试其他形式,创建一个部分并将此部分添加到模板但这失败了.

$phpWord = new PhpWord();
$section = $phpWord->createSection();   

$section->addImage('img.jpg', array('width'=>210, 'height'=>210, 'align'=>'center'));
$template = new TemplateProcessor('form.docx'); 
$template->setValue('image',$section).
Run Code Online (Sandbox Code Playgroud)

有人知道如何使用模板将图像放入.docx吗?

谢谢.

php docx phpword

5
推荐指数
1
解决办法
6732
查看次数

使用PHP和PHPWord将HTML代码转换为doc

我正在使用PHPWord加载docx模板并替换标签{test}.这工作得非常好.

但我想用html代码替换值.不可能直接将其替换为模板.据我所知,现在有使用PHPWord的方法.

我看了htmltodocx.但它接缝它也无法工作,是否可以将代码的和平转换<p>Test<b>test</b><br>test</p>为工作的doc标记?我只需要基本代码,没有样式.但Linebreaks必须工作.

html php openxml phpword

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

在PHPWord 0.12.0中将表格单元格中的文本对齐到右侧

我正在使用PHPWord 0.12.0.我创建了一个表,但似乎无法在单元格中对齐文本.这是我特定行的代码:

$table->addCell(1540, array('bgColor' => 'dddddd'))->addText(htmlspecialchars("Testing", array('align' => 'right')));
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

$table->addCell(1540, array('bgColor' => 'dddddd', 'align' => 'right'))->addText(htmlspecialchars("Testing"));
Run Code Online (Sandbox Code Playgroud)

背景颜色显示正常,但我无法使对齐工作.表格单元格的规格中没有"对齐",那么正确的方法是什么?

phpword

5
推荐指数
1
解决办法
5712
查看次数

PHPWord addTOC 不显示页码

我正在使用https://github.com/PHPOffice/PHPWord生成一个 word 文档。函数 addTOC 生成带有标题的页面索引,但由于某种原因页码不显示。

// add table of contents
$section->addTOC();
Run Code Online (Sandbox Code Playgroud)

结果是:

目录

如果我在标题存在的页面上回显页码,它们显示得很好。但它们不会显示在 TOC 中。我检查以确认文本不是白色的。

phpword phpoffice

5
推荐指数
1
解决办法
2767
查看次数

PHP Word,将生成的文件作为输出发送到浏览器,而无需将其保存在光盘上

我正在使用PHP Word和htmltodocx_converter创建Word文档,一切正常,但是我只需要一个示例,说明如何将文件发送到浏览器以进行下载而不将其保存在光盘上。我看到的所有示例都将文件保存到光盘中:

// Save File
$h2d_file_uri = tempnam( "", "htd" );
$objWriter = PHPWord_IOFactory::createWriter( $phpword_object, "Word2007" );
$objWriter->save( $filename ); // At this line, I would like to output the file to the browser
Run Code Online (Sandbox Code Playgroud)

有人知道我如何将文件实时输出到浏览器?

php phpword

5
推荐指数
1
解决办法
5963
查看次数

如何用php编辑word文档?

我的计算机中有一个现有的 Word 文档,并且喜欢从我的网站(使用 PHP)编辑此文件。我能够找到,PHPWORD但这仅涉及新文件。我不想PHP为整个文档编码,而是希望将它用于不同的内容。

有人知道出路吗?

php ms-word phpword

5
推荐指数
2
解决办法
2万
查看次数

每页表格标题 Word PHPWord

我正在使用 PHPWord 生成报告,但我找不到在每个页面中保留表标题的方法。问题是我可以\xc2\xb4t 为单元格提供样式,并且标题和主表之间有一些空间。

\n\n

我尝试这样做,但我认为这不是最好的解决方案:

\n\n
<?php\nrequire_once \'PHPWord.php\';\n\n// New Word Document\n$PHPWord = new PHPWord();\n\n// New portrait section\n$section = $PHPWord->createSection();\n\n// Define table style arrays\n$styleTable = array(\'borderSize\'=>6, \'borderColor\'=>\'006699\', \'cellMargin\'=>80);\n$styleFirstRow = array(\'borderBottomSize\'=>18, \'borderBottomColor\'=>\'0000FF\', \'bgColor\'=>\'66BBFF\');\n\n// Define cell style arrays\n$styleCell = array(\'valign\'=>\'center\');\n$styleCellBTLR = array(\'valign\'=>\'center\', \'textDirection\'=>PHPWord_Style_Cell::TEXT_DIR_BTLR);\n\n// Define font style for first row\n$fontStyle = array(\'bold\'=>true, \'align\'=>\'center\');\n\n// Add table style\n$PHPWord->addTableStyle(\'myOwnTableStyle\', $styleTable, $styleFirstRow);\n$header = $section->createHeader();\n$table = $header->addTable();\n$table->addRow(900);\n$table->addCell(2000,$styleCell)->addText(\'Row1\',$fontStyle);\n$table->addCell(2000,$styleCell)->addText(\'Row2\',$fontStyle);\n$table->addCell(2000,$styleCell)->addText(\'Row3\',$fontStyle);\n$table->addCell(2000,$styleCell)->addText(\'Row4\',$fontStyle);\n$table->addCell(500,$styleCell)->addText(\'Row5\',$fontStyle);\n// Add table\n$table = $section->addTable(\'myOwnTableStyle\');\n\n// Add more rows / cells\nfor($i = 1; $i <= 1000; $i++) {\n    $table->addRow();\n    $table->addCell(2000)->addText("Cell $i");\n    $table->addCell(2000)->addText("Cell $i");\n …
Run Code Online (Sandbox Code Playgroud)

php each phpword

5
推荐指数
1
解决办法
4365
查看次数

在 PhpWord 中创建表

一切工作正常,但我真的尝试在 phpword 中制作一个表格,表格内的文本下方没有空白间距。请帮我解决这种情况。

这是我的代码......

$phpWord = new \PhpOffice\PhpWord\PhpWord();

$phpWord->getCompatibility()->setOoxmlVersion(14);
$phpWord->getCompatibility()->setOoxmlVersion(15);

$targetFile = "./global/uploads/";
$filename = $news['CompanyDetails']['QuotationCode'].' Quotation For '.$news['CompanyDetails']['CompanyName'].'.docx';

$section = $phpWord->addSection();
$section->getStyle()->setBreakType('continuous');
$header = $section->addHeader();
$header->headerTop(10);



$section->addImage(base_url('images/qoutlogo.jpg'), array('align'=>'center' ,'topMargin' => -5));

$section->addTextBreak(-5);
$center = $phpWord->addParagraphStyle('p2Style', array('align'=>'center','marginTop' => 1));
$section->addText('this is my name',array('bold' => true,'underline'=>'single','name'=>'TIMOTHYfont','size' => 14),$center);
$section->addTextBreak(-.5);

$section->addText('Tel:    00971-55-25553443 Fax: 00971-55- 2553443',array('name'=>'Times New Roman','size' => 13),$center);
$section->addTextBreak(-.5);
$section->addText('Quotation',array('bold' => true,'underline'=>'single','name'=>'Times New Roman','size' => 16),$center);
$section->addTextBreak(-.5);
$tableStyle = array('borderSize' => 1, 'borderColor' => '999999', 'afterSpacing' => 0, 'Spacing'=> 0, 'cellMargin'=>0 …
Run Code Online (Sandbox Code Playgroud)

php codeigniter phpword

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

删除块/替换块不起作用

我在使用 PHPWord 扩展时遇到了一个问题 我正在尝试使用 Yii2 和 PHPWord 从 template.docx 文件生成 cv.docx 文件。

这是我的模板文件中要替换的内容:

${EXPERIENCES}
${/EXPERIENCES}
Run Code Online (Sandbox Code Playgroud)

这是我的 php 文件中的代码

Settings::setZipClass(Settings::PCLZIP);

$template_document= 'template.docx';
$templateProcessor = new TemplateProcessor($template_document);
$workExperiences = [
    [
        'company' => 'PiRails - TechHub Connect',
        'title' => 'Junior PHP-Laravel Developer',
        'started_at' => 'June 2016',
        'ended_at' => 'Dec 2016',
    ],
    [
        'company' => 'FreeLancer',
        'title' => 'PHP, Asp.Net Full stack Developer',
        'started_at' => 'Jan 2015',
        'ended_at' => '',
    ],
    [
        'company' => 'FreeLancer',
        'title' => 'PHP, Asp.Net Full stack Developer',
        'started_at' …
Run Code Online (Sandbox Code Playgroud)

php phpword yii2 yii2-advanced-app

5
推荐指数
0
解决办法
1372
查看次数

没有作曲家的 PHPWord 安装

原谅这里看似蹩脚的地方。我正在使用只能访问 cpanel 的共享主机,主机不愿意代表我安装 Composer 或 PHPWord。是否可以通过从 github 下载 ZIP 来安装 PHPWord?谢谢

php phpword

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

标签 统计

phpword ×10

php ×8

codeigniter ×1

docx ×1

each ×1

html ×1

ms-word ×1

openxml ×1

phpoffice ×1

yii2 ×1

yii2-advanced-app ×1