phpword

订单导出pdf文件

荒凉一梦 提交于 2020-04-21 13:35:11
原理 原始数据->加载模板->临时文件->PDF文件 方案准备 html模板转pdf 难点:1. 每次变化都要找设计师;2. html样式很难控制(个人不擅长);3.html转pdf样式难以控制 word模板转pdf 难点:1. 合适插件的选择;2. 中文的处理 最终选择,word模板模式 实现步骤 WORD插件 开源地址 composer require phpoffice/phpword phpword非常好用,支持变量,太方便了。 WORD转PDF插件 下载地址 /opt/libreoffice6.4/program/soffice 完整demo //生成订单pdf public function order_pdf_f() { #1. 准备订单信息 $person_addr = "北京市"; $person_name = "张三"; $person_mobile= "18932000000"; #2. 生成素材文件 $res_dir_path = './res/'; $templateFile = $res_dir_path.'temp_order.docx'; $wordPath = $res_dir_path.'tmp/hello.docx';//计算机上的一个文件 try { $templateProcessor = new \PhpOffice\PhpWord

Split string into bbcode sections. PHP [duplicate]

爱⌒轻易说出口 提交于 2020-02-29 09:22:27
问题 This question already has an answer here : PHP BBCode Parser (1 answer) Closed 20 days ago . I have a BBcode wysiwyg editor for only the basics styles bold, italic and underline. I need to take the stored data from it and use it to convent it into a PHPWord friendly array. PHPWord works with something called textrun so to have many styles within a line you would simple do something like... $PHPWordTextRun = new TextRun(); $PHPWordTextRun->addText('This is some text that contains ', 'NORMAL');

关于phpword使用的小记

我们两清 提交于 2020-02-29 07:32:11
phpword的功能有点简单,如果要开发复杂点的需要进行二次开发。 http://phpword.codeplex.com/ [关于乱码问题处理] 中文乱码问题,这个一定是存在的,如果php环境已经是utf8了,要找到关键地方,转utf8的代码,去掉,否则就是转两次编码了, 典型的是phpword\template.php文件,把这行注释掉:$replace = utf8_encode($replace); 开发时可以参考: http://wenku.baidu.com/view/2c63938edd88d0d233d46aa6.html 中文开发手册 来源: https://www.cnblogs.com/tecliu/p/3602392.html

phpword的几个坑

谁说我不能喝 提交于 2020-02-25 10:45:47
下载地址http://phpword.codeplex.com/ 开发目的:有现成的word模板 替换模板中的字段 1.中文乱码问题,如果你文件本身就是utf8.。。把Phpword里的模板类的一行转码代码注释了,即可解决。 PHPWord文件夹里的Template.php文件的$replace = utf8_encode($replace);这行代码注释掉 2.也是最坑的,在模板中写变量的时候,一定要在外边写好,然后复制进来,千万别在word中编辑,别问为什么,这个坑 坑了我好半天。 $model=new PHPWord(); $doc=$model->loadTemplate("test.docx"); $doc->setValue('name','小桥海风'); $doc->setValue('username','inc'); $doc->setValue('password','659'); $doc->save('test1.docx'); word中变量 ${name} ${username} ${password} 来源: https://www.cnblogs.com/inc-is-include/p/5387310.html

How to merge cells in PHPWord? Or to have different number of cells in each table row?

拟墨画扇 提交于 2020-02-22 12:50:08
问题 Trying to create MS Word document using PHP library PHPWord. Can you help me how to merge two or more cells in document? Or how to have different number of cells in each table row? I tried with cell definition as: $cell11 = array('gridSpan'=>2); But it did not worked.... Thank you in advance! 回答1: Add code like this 1. PHPWord/Section/Table/Cell.php /** * How many columns this cell spans * @var int */ private $_gridSpan; public function__construct($insideOf,$pCount,$width=null,$style=null,

Why Office OpenXML splits text between tags and how to prevent it?

末鹿安然 提交于 2020-02-20 09:40:09
问题 I'm currently trying to work with docx files using PHPWord library and its templating system. I have found and updated someones (cant remember the name, but its not important) path to this library that can work with tables (replicate its rows and then use standard setValue() from PHPWord on each of row). If i create my own document, the data in xml is in normal structure, so the variable to be replaced ${variable} is in its own tag like this: <w:tbl> <w:tr> ... ${variable} </w:tr> </w:tbl> I

PHPWord 操作word ZipArchive::locateName(): Invalid or uninitialized Zip object

一世执手 提交于 2020-02-07 02:15:30
PHPWord 操作 word文档报错ZipArchive::locateName(): Invalid or uninitialized Zip object总结 一、文件问题 我碰到的就是第一种情况了,docx文件有问题,office文件经过编辑后都会被加密了,于是我新建了一个文件,报错就消失了,但是如何对加密文件进行编辑,仍然无法解决…… 二、MsDoc跟Word2007的区别 MsDoc读取的是.doc后缀,适用于2003年前的MicrosoftOffice版本的word文件,对于现在来说已经很老了,Word2007读取的是docx后缀,现在基本使用的是Word2007了。 适用于两种后缀文件的代码,如果是因为这个原因报错的话,问题是很好解决的。 if ( 'docx' == $file_ext ) { $inputFileType = 'Word2007' ; //Word2007及以上 } else { // $this->openOfficePreview($inputFileName);//调用openoffice处理吧 $inputFileType = 'MsDoc' ; //Word97-2003 但是会乱码 何解? TODO } 附带下安装PHPWord安装教程(镜像比较坑,下半天……) 1.安装composer就不赘述了,自行百度 2.在composer

WrappingStyle/Align Image not working in a header section

混江龙づ霸主 提交于 2020-01-25 01:55:29
问题 I'm currently working with PhpWord. I added a header section, and inside it, added two images. Images need to be aligned, one left and the other right, but in the same line. And I have this code but only prints the images one below the other, only way I can change them is insde the .docx file. $header = $section->addHeader(); $header->addImage('http://localhost/doWords/logoRenatea.jpg', array( 'width' => '291', 'height' => '81', 'align' => 'left', 'marginTop' => -1, 'marginLeft' => -1,

Generate PDF from .docx generated by PHPWord

南楼画角 提交于 2020-01-12 14:08:22
问题 I am creating .docx files from a template using PHPWord . It works fine but now I want to convert the generated file to PDF . First I tried using tcpdf in combination with PHPWord $wordPdf = \PhpOffice\PhpWord\IOFactory::load($filename.".docx"); \PhpOffice\PhpWord\Settings::setPdfRendererPath(dirname(__FILE__)."/../../Office/tcpdf"); \PhpOffice\PhpWord\Settings::setPdfRendererName('TCPDF'); $pdfWriter = \PhpOffice\PhpWord\IOFactory::createWriter($wordPdf , 'PDF'); if (file_exists($filename."

Generate PDF from .docx generated by PHPWord

佐手、 提交于 2020-01-12 14:07:46
问题 I am creating .docx files from a template using PHPWord . It works fine but now I want to convert the generated file to PDF . First I tried using tcpdf in combination with PHPWord $wordPdf = \PhpOffice\PhpWord\IOFactory::load($filename.".docx"); \PhpOffice\PhpWord\Settings::setPdfRendererPath(dirname(__FILE__)."/../../Office/tcpdf"); \PhpOffice\PhpWord\Settings::setPdfRendererName('TCPDF'); $pdfWriter = \PhpOffice\PhpWord\IOFactory::createWriter($wordPdf , 'PDF'); if (file_exists($filename."