2017 © Pedro Peláez
 

library phpword

PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)

image

alxishin/phpword

PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)

  • Monday, June 25, 2018
  • by alxishin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1423 Forks
  • 0 Open issues
  • 14 Versions
  • 0 % Grown

The README.md

PHPWord

Latest Stable Version Build Status Code Quality Code Coverage Total Downloads License, (*1)

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., (*2)

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 and the API Documentation., (*3)

Read more about PHPWord:, (*4)

Features

With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your PHP 5.3+ scripts. Below are some of the things that you can do with PHPWord library:, (*5)

  • Set document properties, e.g. title, subject, and creator.
  • Create document sections with different settings, e.g. portrait/landscape, page size, and page numbering
  • Create header and footer for each sections
  • Set default font type, font size, and paragraph style
  • Use UTF-8 and East Asia fonts/characters
  • Define custom font styles (e.g. bold, italic, color) and paragraph styles (e.g. centered, multicolumns, spacing) either as named style or inline in text
  • Insert paragraphs, either as a simple text or complex one (a text run) that contains other elements
  • Insert titles (headers) and table of contents
  • Insert text breaks and page breaks
  • Insert and format images, either local, remote, or as page watermarks
  • Insert binary OLE Objects such as Excel or Visio
  • Insert and format table with customized properties for each rows (e.g. repeat as header row) and cells (e.g. background color, rowspan, colspan)
  • Insert list items as bulleted, numbered, or multilevel
  • Insert hyperlinks
  • Insert footnotes and endnotes
  • Insert drawing shapes (arc, curve, line, polyline, rect, oval)
  • Insert charts (pie, doughnut, bar, line, area, scatter, radar)
  • Insert form fields (textinput, checkbox, and dropdown)
  • Create document from templates
  • Use XSL 1.0 style sheets to transform main document part of OOXML template
  • ... and many more features on progress

Requirements

PHPWord requires the following:, (*6)

Installation

It is recommended that you install the PHPWord library through composer. To do so, add the following lines to your composer.json., (*7)

{
    "require": {
       "phpoffice/phpword": "dev-master"
    }
}

Alternatively, you can download the latest release from the releases page. In this case, you will have to register the autoloader., (*8)

require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();

Getting started

The following is a basic usage example of the PHPWord library., (*9)

<?php
require_once 'src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();

// Creating the new document...
$phpWord = new \PhpOffice\PhpWord\PhpWord();

/* Note: any element you append to a document must reside inside of a Section. */

// Adding an empty Section to the document...
$section = $phpWord->addSection();
// Adding Text element to the Section having font styled by default...
$section->addText(
    htmlspecialchars(
        '"Learn from yesterday, live for today, hope for tomorrow. '
            . 'The important thing is not to stop questioning." '
            . '(Albert Einstein)'
    )
);

/*
 * Note: it's possible to customize font style of the Text element you add in three ways:
 * - inline;
 * - using named font style (new font style object will be implicitly created);
 * - using explicitly created font style object.
 */

// Adding Text element with font customized inline...
$section->addText(
    htmlspecialchars(
        '"Great achievement is usually born of great sacrifice, '
            . 'and is never the result of selfishness." '
            . '(Napoleon Hill)'
    ),
    array('name' => 'Tahoma', 'size' => 10)
);

// Adding Text element with font customized using named font style...
$fontStyleName = 'oneUserDefinedStyle';
$phpWord->addFontStyle(
    $fontStyleName,
    array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
);
$section->addText(
    htmlspecialchars(
        '"The greatest accomplishment is not in never falling, '
            . 'but in rising again after you fall." '
            . '(Vince Lombardi)'
    ),
    $fontStyleName
);

// Adding Text element with font customized using explicitly created font style object...
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
$fontStyle->setBold(true);
$fontStyle->setName('Tahoma');
$fontStyle->setSize(13);
$myTextElement = $section->addText(
    htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)')
);
$myTextElement->setFontStyle($fontStyle);

// Saving the document as OOXML file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx');

// Saving the document as ODF file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
$objWriter->save('helloWorld.odt');

// Saving the document as HTML file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');
$objWriter->save('helloWorld.html');

/* Note: we skip RTF, because it's not XML-based and requires a different example. */
/* Note: we skip PDF, because "HTML-to-PDF" approach is used to create PDF documents. */

:warning: Escape any string you pass to OOXML/ODF/HTML document, otherwise it may get broken., (*10)

More examples are provided in the samples folder. You can also read the Developers' Documentation and the API Documentation for more detail., (*11)

Contributing

We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute., (*12)

The Versions

25/06 2018

dev-develop

dev-develop http://phpoffice.github.io

PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

template php html pdf writer openxml reader word doc office odt docx phpoffice odf ooxml rtf phpword office open xml iso iec 29500 wordprocessingml rich text format opendocument template processor

04/04 2017

1037.x-dev

1037.9999999.9999999.9999999-dev http://phpoffice.github.io

PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

template php html pdf writer openxml reader word doc office odt docx phpoffice odf ooxml rtf phpword office open xml iso iec 29500 wordprocessingml rich text format opendocument template processor

30/08 2015

dev-master

9999999-dev http://phpoffice.github.io

PHPWord - A pure PHP library for reading and writing word processing documents (DOCX, ODT, RTF, HTML, PDF)

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.3.3
  • ext-xml *

 

The Development Requires

template php html pdf writer openxml reader word doc office odt docx phpoffice ooxml rtf phpword office open xml iso iec 29500 wordprocessingml rich text format opendocument template processor

30/08 2015

v0.12.1

0.12.1.0 http://phpoffice.github.io

PHPWord - A pure PHP library for reading and writing word processing documents (DOCX, ODT, RTF, HTML, PDF)

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.3.3
  • ext-xml *

 

The Development Requires

template php html pdf writer openxml reader word doc office odt docx phpoffice ooxml rtf phpword office open xml iso iec 29500 wordprocessingml rich text format opendocument template processor

03/01 2015

0.12.0

0.12.0.0 http://phpoffice.github.io

PHPWord - A pure PHP library for reading and writing word processing documents (DOCX, ODT, RTF, HTML, PDF)

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.3.3
  • ext-xml *

 

The Development Requires

template php html pdf writer openxml reader word doc office odt docx phpoffice ooxml rtf phpword office open xml iso iec 29500 wordprocessingml rich text format opendocument template processor

02/06 2014

0.11.1

0.11.1.0 http://phpoffice.github.io

PHPWord - A pure PHP library for reading and writing word processing documents (DOCX, ODT, RTF, HTML, PDF)

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.3.3
  • ext-xml *

 

The Development Requires

template php html pdf writer openxml reader word doc office odt docx phpoffice ooxml rtf phpword office open xml iso iec 29500 wordprocessingml rich text format opendocument

01/06 2014

0.11.0

0.11.0.0 http://phpoffice.github.io

PHPWord - A pure PHP library for reading and writing word processing documents (DOCX, ODT, RTF, HTML, PDF)

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.3.3
  • ext-xml *

 

The Development Requires

template php html pdf writer openxml reader word doc office odt docx phpoffice ooxml rtf phpword office open xml iso iec 29500 wordprocessingml rich text format opendocument

21/05 2014

0.10.1

0.10.1.0 http://phpoffice.github.io

PHPWord - Read, Create, and Write DOCX, ODT, and RTF documents in PHP

  Sources   Download

LGPL-2.1+

The Requires

  • php >=5.3.3
  • ext-xml *

 

The Development Requires

template php writer openxml reader word doc office odt docx phpoffice ooxml rtf phpword office open xml iso iec 29500 wordprocessingml rich text format opendocument

04/05 2014

0.10.0

0.10.0.0 http://phpoffice.github.io

PHPWord - Read, Create, and Write DOCX, ODT, and RTF documents in PHP

  Sources   Download

LGPL-2.1+

The Requires

  • php >=5.3.3
  • ext-xml *
  • ext-zip *

 

The Development Requires

template php writer openxml reader word doc office odt docx phpoffice ooxml rtf phpword office open xml iso iec 29500 wordprocessingml rich text format opendocument

27/03 2014

0.9.1

0.9.1.0 http://phpoffice.github.io

PHPWord - Read, Create, and Write DOCX, ODT, and RTF documents in PHP

  Sources   Download

LGPL-3.0+

The Requires

  • php >=5.3.3
  • ext-xml *
  • ext-zip *

 

The Development Requires

template php writer openxml reader word doc office odt docx phpoffice ooxml rtf phpword office open xml iso iec 29500 wordprocessingml rich text format opendocument

26/03 2014

0.9.0

0.9.0.0 http://phpoffice.github.io

PHPWord - Read, Create, and Write DOCX, ODT, and RTF documents in PHP

  Sources   Download

LGPL-3.0+

The Requires

  • php >=5.3.3
  • ext-xml *
  • ext-zip *

 

The Development Requires

template php writer openxml reader word doc office odt docx phpoffice ooxml rtf phpword office open xml iso iec 29500 wordprocessingml rich text format opendocument

16/03 2014

0.8.1

0.8.1.0 http://phpoffice.github.io

PHPWord - Read, Create and Write Word documents in PHP

  Sources   Download

LGPL

The Requires

  • php >=5.3.0
  • ext-xml *
  • ext-zip *

 

The Development Requires

php writer word doc docx rtf

15/03 2014

0.8.0

0.8.0.0 http://phpoffice.github.io

PHPWord - Read, Create and Write Word documents in PHP

  Sources   Download

LGPL

The Requires

  • php >=5.3.0
  • ext-xml *
  • ext-zip *

 

The Development Requires

php writer word doc docx rtf

28/01 2014

0.7.0

0.7.0.0 http://phpoffice.github.io

PHPWord - Read, Create and Write Word documents in PHP

  Sources   Download

LGPL

The Requires

  • php >=5.3.0
  • ext-xml *

 

php writer word doc docx rtf