phpword

PHPWord - set line spacing to “single”

纵饮孤独 提交于 2021-02-08 05:28:37
问题 I have to generate some word docs with PHP and need to change the line spacing and line height. Setting the line height is simple, but I have no idea how I change change the line spacing from "multiple" to "single". (I hope I use the right terms here because I got only a german word version...) I've added a picture to make clear which option I mean... 回答1: You can set the spacing styles (including line spacing) with the paragraph style - you just need to define the value in twips... for

When using PHPWord can I format inline text when calling addListItem?

浪子不回头ぞ 提交于 2021-01-29 03:38:36
问题 I'm using PHPWord (https://github.com/PHPOffice/PHPWord/tree/develop) to generate a number of bulleted items appearing within a Word document. I am relying on addListItem() to add the bullet items to the document and that is working just fine. The only problem I'm having is that I also need format some of the text appearing in the bulleted item with a bold word appearing first followed by non-bold text appearing afterwards; all within the same line. For example: bold word: more information

PHP:引用Phpword导出数据到word文档

扶醉桌前 提交于 2020-11-21 03:11:35
下载地址https://www.cnwenhui.cn/html/show-597.html(其中有中文使用手册可以下载看看) 1.首先要下载Phpword类库,放在如下图目录下 2.调用方法 1 public function daochuword() 2 { 3 vendor("PHPWord.PHPWord" ); 4 // New Word Document 5 $PHPWord = new \PHPWord(); 6 // New portrait section 7 $section = $PHPWord -> createSection(); 8 $PHPWord ->addFontStyle('rStyle', array ('bold'=> true ,'color'=>'87CEEB','size'=>35 )); 9 $PHPWord ->addParagraphStyle('pStyle', array ('align'=>'center','spacing'=>120 )); 10 $xlsModel = M('api_aliucheng' ); 11 $Data = $xlsModel ->Field('id,u_name,u_addres,u_tel,u_card,u_time,u_imgz,u_imgf,u_class,b_one_beizhu,b

PHPWord导出word文档

心不动则不痛 提交于 2020-11-19 04:57:11
最近接了个把数据导出到word文档的需求,之前一直都是使用PHPExcel库导出excel的,还是头次接到导出到word文档的需求,我想既然有PHPExcel,那么肯定也会有PHPWord库吧,在网上一搜,还真有!而且都是phpoffice家的。看了下文档,最终决定使用模板的方式来导出数据,感觉也是最简单的一种方式了。 过程如下: 使用composer下载PHPWord到项目中 composer require phpoffice/phpword 可以看到,phpword的下载量还是挺高的 下载完后就可以开始制作我们的需求模板了,如下图所示,模板中使用 ${变量名} 作为占位符,到时候用代码替换即可,${company_name}、${pic}等都是占位符 制作好模板就可以开始写代码了。 //导出word大致可以分为三步 //1.创建模板对象 $document = new TemplateProcessor('./template.docx'); //2.插入数据 //插入文字 $document->setValue('company_name', 'XXX有限公司'); //插入图片 $document->setImageValue('pic1', './img/gyy.jpeg'); $document->setImageValue('pic2', './img/zyt

PHP读取word docx文档内容及处理图片

给你一囗甜甜゛ 提交于 2020-07-27 18:58:03
PHP读取word文档里的文字及图片,并保存 一、composer安装phpWord composer require phpoffice/phpword 传送门: https://packagist.org/packages/phpoffice/phpword 二、phpWord 读取 docx 文档( 注意是docx格式,doc格式不行 ) 如果你的文件是doc格式,直接另存为一个docx就行了;如果你的doc文档较多,可以下一个批量转换工具: http://www.batchwork.com/en/doc2doc/download.htm 如果你还没配置自动加载,则先配置一下: require './vendor/autoload.php'; 加载文档: $dir = str_replace ('\\', '/', __DIR__) . '/' ; $source = $dir . 'test.docx' ; $phpWord = \PhpOffice\PhpWord\IOFactory::load( $source ); 三、关键点 1)对齐方式:PhpOffice\PhpWord\Style\Paragraph -> getAlignment() 2)字体名称:\PhpOffice\PhpWord\Style\Font -> getName() 3)字体大小:

Is PHPWord suitable for direct mail?

不羁岁月 提交于 2020-07-10 08:56:31
问题 Is PHPWord suitable for direct mail? (also named Mail Merge in MS Office Word) Here is the process I want to automat: .docx documents are provided to the application. They are formatted for direct mail with fixed parts and a collection of merge fields. For each document, the application will search for the data in several databases, then create the custom documents. 回答1: found this http://phpword.readthedocs.io/en/latest/templates-processing.html Efficient but does not use native word merge

PhpWord doesn't replace text

一世执手 提交于 2020-07-05 02:43:06
问题 I have a docx file and I need to replace some text. This is done inside codeigniter framework; here is the code: $this->load->library('word'); $template = $this->word->loadTemplate($_SERVER['DOCUMENT_ROOT'].'/doc/assets/doc3.docx'); $template->setValue('replacename', 'new'); $template->save($_SERVER['DOCUMENT_ROOT'].'/doc/assets/helloWorld.docx'); When I open the new file I still get "replacename" instad of "new". "replacename" is formatted with Verdana font, 9pt font size (no underline or