PHPWord | pure PHP library for reading and writing word processing | Document Editor library

 by   PHPOffice PHP Version: 1.1.0 License: Non-SPDX

kandi X-RAY | PHPWord Summary

kandi X-RAY | PHPWord Summary

PHPWord is a PHP library typically used in Editor, Document Editor applications. PHPWord has no bugs, it has no vulnerabilities and it has medium support. However PHPWord has a Non-SPDX License. You can download it from GitHub.

PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft Office Open XML (OOXML or OpenXML), OASIS Open Document Format for Office Applications (OpenDocument or ODF), Rich Text Format (RTF), HTML, and PDF. PHPWord is an open source project licensed under the terms of LGPL version 3. PHPWord is aimed to be a high quality software product by incorporating continuous integration and unit testing. You can learn more about PHPWord by reading the Developers' Documentation. If you have any questions, please ask on StackOverFlow.

            kandi-support Support

              PHPWord has a medium active ecosystem.
              It has 6704 star(s) with 2592 fork(s). There are 315 watchers for this library.
              There were 1 major release(s) in the last 12 months.
              There are 1001 open issues and 621 have been closed. On average issues are closed in 539 days. There are 98 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of PHPWord is 1.1.0

            kandi-Quality Quality

              PHPWord has 0 bugs and 0 code smells.

            kandi-Security Security

              PHPWord has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              PHPWord code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              PHPWord has a Non-SPDX License.
              Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.

            kandi-Reuse Reuse

              PHPWord releases are available to install and integrate.
              Installation instructions, examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi has reviewed PHPWord and discovered the below as its top functions. This is intended to give you an instant insight into PHPWord implemented functionality, and help decide if they suit your requirements.
            • Reads a block of FCF data
            • Parse a list of options
            • Parse attribute style
            • Get list type style
            • Write the style
            • Read a run child node
            • Write Plot Area
            • Write the font scheme
            • Write the default styles
            • Set an image value
            Get all kandi verified functions for this library.

            PHPWord Key Features

            No Key Features are available at this moment for PHPWord.

            PHPWord Examples and Code Snippets

            No Code Snippets are available at this moment for PHPWord.

            Community Discussions


            Is there a way to get sections from an IOFactory?
            Asked 2021-Nov-03 at 09:19

            I'm using PHPWord to use a template but when I save my file in HTML format I only see its body and not the header or footer. So I would like to get these sections to insert them in the HTML part



            Answered 2021-Nov-03 at 09:19

            You can't. A quote from one of the contributors:

            Header & Footer are only applicable when printing pages, which is not the case for HTML.




            i extend class want exten contructor laravel. php
            Asked 2021-Oct-28 at 07:40

            i extend class want exten contructor laravel. php i extend class want exten contructor laravel. i extend class want exten contructor laravel. contructor class children



            Answered 2021-Oct-28 at 07:40

            You have to pass the param to parent::__construct(); in your extend class.

            So that:



            alignment is not working in phpWord TemplateProcessor
            Asked 2021-Oct-07 at 12:42

            I am trying to change the alignment of the image added into the docx file, but the alignment is not working. I have tried as below:



            Answered 2021-Oct-07 at 12:42

            You are using positionning settings reserved when you create a Word document from scratch using the library.

            However, you are using PHPWord templating processing capability : that means the layout is driven by your Word document itself.

            So, the placeholder itself must be centered in the template to be replaced by a centered image.

            To illustrate, consider the code below (placed in any PHP code where TemplateProcessor class is available) :



            PHPWord : Is it possible to replace placeholder text in a document with an image (at the same position where the text was)?
            Asked 2021-Sep-07 at 17:12

            As part of the implementation of an electronic signature function. I need to add the signature at a specific position in the Word document. The position however could vary from one document to another. The only potential solution to this seems to be having a signature placeholder which gets replaced with the signature.png once the document is signed.

            Is this possible with the PHPWord package ? If not is there any package out there that can do this ?



            Answered 2021-Sep-07 at 17:12

            This is how to do it with phpword, as per their documentation :

            First, the word file needs to have a placeholder :



            How to PHPWord foreach codeBlock
            Asked 2021-Sep-04 at 10:32

            I need to convert the data in the MYSQL database to Word.

            Word file

            My code



            Answered 2021-Sep-04 at 10:32

            It didn't work because I used a much older PHPWord. I have installed a new PHPword and everything is working fine



            PHPWord template processing with block row cloning inside a block clone
            Asked 2021-Sep-02 at 16:17

            I'm using PHPWord to create reports that make use of a .docx template.

            This library allows me to clone a block and clone table rows. However the examples are separate from each other. I need to combine both approaches because my template table looks like this:



            Answered 2021-Sep-02 at 16:17

            After countless attempts I finally figured a way to do this (not really sure if it's the best approach, but it works).


            Assuming my data looks like this:



            Why does PHPword setvalue not replacing text in word Doc?
            Asked 2021-Aug-04 at 10:02

            I am trying to edit word document using php (PHPword library). However, I am not sure why it is not working. The script did not throw any error.

            My Code:



            Answered 2021-Aug-04 at 08:43

            The setValue() method will set the value but not return it to var_dump it.

            Instead you can add:



            generate template from database
            Asked 2021-Jul-19 at 05:00

            I'm trying to work with the PhpWord library for generating a Word file using Laravel.

            I search for the documentation of this library and how it worked, I found that I should have already a template to work with.

            But In my case, I should create this template from the database and then generate this file in word format.

            I'm trying the following code :



            Answered 2021-Jul-19 at 02:35
            $preambule = DB::table('modele_contrat')->where('id_modele_contrat', $value['id_modele_contrat'])->value('preambule');
            $phpWord = new \PhpOffice\PhpWord\PhpWord();
            $sectionStyle = array(
                //'orientation'       =>      'landscape',
                'marginTop'         =>      600,
                'marginRight'       =>      600,
                'marginBottom'      =>      600,
                'marginLeft'        =>      600,
                //'text-align'        =>      'right',
                'footerHeight'      =>      100
            $section = $phpWord->addSection($sectionStyle);
            $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
            try {
            } catch (Exception $e) {
            return response()->download(storage_path('preambule.docx'));



            Create array of associated arrays with same key using PHP
            Asked 2021-Jul-01 at 05:11

            This is code that produces the array of associated arrays that I need to input into a PHPWord cloneBlock() routine.



            Answered 2021-Jul-01 at 04:49


            Issue converting to .pdf a merged .docx file that opens fine in Word
            Asked 2021-Apr-17 at 14:33

            So, I have the following scenario.

            I am working on a system for academical papers. I have several inputs that are for stuff like author name, coauthors, title, type of paper, introduction, objectives and so on. I store all that information in a database. The user has a Preview button which when clicked, generates a Word asynchronously and sends the file location back to the user and that file is afterwards shown to the user in an iframe using Google Doc Viewer.

            There's a specific use case where the user/author of the paper can attach a .docx file with a table, or a .jpeg file for a figure. That table/figure has to be included inside the final .docx file.

            For the .docx generation process I am using PHPWord.

            So up until this point everything works fine, but my issues start when I try to mix everything and put together the .docx file.

            Approach Number One

            My first approach on doing this was to do everything with PHPWord. I create the file, add the texts where required and in the case of the image just insert the image and after that the figure caption below the image.

            Things get tricky though, when I try doing the same thing with the .docx table file. My only option was to get the table XML using this. It did the trick, but the problem I ran into was that when I opened the resulting Word file, the table was there, but had lost all of its styling and had transparent borders. Because of those transparent borders, afterwards when converting it to PDF the borders were ignored and the table info is just scrambled text.

            Approach Number Two (current one)

            After fighting with Approach Number One and just complicating stuff more, I decided to do something different. Since I already generated one docx file with the main paper information and I needed to add another docx file, I decided to use the DocX Merge Library.

            So, what i basically did was I have three generated word files, one for the main paper information, one for the table and one for the table caption (that last one is mainly to not overcomplicated the order of information). Also, that data is not in the table .docx file.

            Then I run this:



            Answered 2021-Apr-17 at 14:33

            After a lot of attempts to fix it, I wasn't able to achieve what I wanted with PHPWord and the merging library I mentioned.

            Since I needed to fix this I decided to invest in the paid library I mentioned in my question. It was an expensive purchase, but for those who are interested, it does exactly what was required and it does it perfectly.

            The two main functions I required were document merging and importing of content to a .docx file.

            So I had to purchase the Premium package. Once there, the library literally does everything for you.

            Example for docx files merge code:


            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install PHPWord

            PHPWord is installed via Composer. To add a dependency to PHPWord in your project, either. Run the following to use the latest stable version. or if you want the latest master version. You can of course also manually edit your composer.json file.
            The following is a basic usage example of the PHPWord library. More examples are provided in the samples folder. For an easy access to those samples launch php -S localhost:8000 in the samples directory then browse to http://localhost:8000 to view the samples. You can also read the Developers' Documentation for more detail.


            We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • HTTPS


          • CLI

            gh repo clone PHPOffice/PHPWord

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link