PHPOffice logo

PHPOffice

  •  0 ratings
In category: Office Suites

About PHPOffice

PHPOffice contains libraries which permits to write and read files from most office suites.

  •   313  
  •   0  
  •   0  
  •   0  
Github stats:
  •  Commits: N/A  
  •   N/A  
  •   N/A  
  •  Latest commit: N/A  

Deploy this app to Linode with a free $100 credit!

Languages/Platforms/Technologies:
Lincenses:

More about PHPOffice

HPOffice is a set of libraries for writing and reading files from most office suites. It contains:

PHPWord

PhpSpreadsheet

PHPPresentation

PHPVisio

PHPExcel

PHPProject

Each of these components has its own project page.

Here is a look at the first component: PHPWord

PHPWord

Latest Stable Version CI Code Quality Code Coverage Total Downloads License Join the chat at https://gitter.im/PHPOffice/PHPWord

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

Read more about PHPWord:

Features

With PHPWord, you can create OOXML, ODF, or RTF documents dynamically using your PHP scripts. Below are some of the things that you can do with PHPWord library:

  • 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 headers, main document part, and footers of an OOXML template
  • ... and many more features on progress

Requirements

PHPWord requires the following:

Installation

PHPWord is installed via Composer. To add a dependency to PHPWord in your project, either

Run the following to use the latest stable version

composer require phpoffice/phpword
or if you want the latest unreleased version
composer require phpoffice/phpword:dev-master

Getting started

The following is a basic usage example of the PHPWord library.

<?php
require_once 'bootstrap.php';

// 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(
    '"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(
    '"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(
    '"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('"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. */

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.

Contributing

We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute.

Comments (0)

Please login to join the discussion on this project.

PHPOffice Reviews (0)

Overall Rating

None

based on 0 ratings

Please login to review this project.

No reviews for this project yet.

↑ back to top

Linux VPS from $11/yr.
RackNerd VPS for $11.38/mo

Popular Projects

FluxBB

in Social Networks and Forums
 29k    0    0    0  

Nextcloud

in File Transfer & Synchronization
 17k    1    1    0  

Libreddit

in Social Networks and Forums
 5k    0    1    0  

CasaOS

in Self-hosting Solutions
 4k    0    0    0  

Audiobookshelf

in Audio Streaming
 3k    0    1    0  

Mediagoblin

in Photo and Video Galleries
 3k    0    0    0  

Dashboard

in Personal Dashboards
 2k    0    0    0  

Most Discussed

Nextcloud

in File Transfer & Synchronization
 17k    1    1    0  

Tube Archivist

in Automation
 2k    0    1    0  

OneDev

in Project Management
 1k    0    0    0  

iodine

in Proxy
 1k    0    0    0  

Alf.io

in Booking and Scheduling
 1k    0    0    0  

sysPass

in Password Managers
 741    0    0    0  

Misskey

in Social Networks and Forums
 2k    0    0    0  
pCloud Lifetime

Top Rated Projects

Gitea

 1 rating
in Project Management

Bagisto

 1 rating
in E-commerce

LinkAce

 1 rating
in Bookmarks and Link Sharing

Pydio

 1 rating
in File Transfer & Synchronization

Audiobookshelf

 1 rating
in Audio Streaming

Nextcloud

 1 rating
in File Transfer & Synchronization

Seafile

 1 rating
in File Transfer & Synchronization

Categories

You May Also Be Interested In

Infinoted logo
Infinoted cover

Infinoted

Server for Gobby, a multi-platform collaborative text edito…

ONLYOFFICE logo
ONLYOFFICE cover

ONLYOFFICE

Office suite that enables you to manage documents, projects…

Collabora Online Development Edition logo
Collabora Online Development Edition cover

Collabora Online Development Edition

Collabora Online Development Edition (CODE) is a powerful L…