How to Troubleshoot Apps for the Modern Connected Worker
What is PHPOffice?
1. Mark Baker
@Mark_Baker
Technical Team Lead at Inviqa
(formerly Ibuildings UK)
Coordinator of Open Source libraries:
PHPExcel,
PHPWord,
PHPPowerPoint,
PHPVisio,
PHPProject
2. PHPOffice
https://github.com/PHPOffice/
Set of PHP Libraries for creating, reading and writing
documents in standard office suite file formats
PHPExcel
PHPWord
PHPPowerPoint
PHPProject
PHPVisio
Licensed under LGPL (GNU LESSER GENERAL PUBLIC LICENSE)
3. PHP Spreadsheet Engine
Major Features
Document Metadata (author, date created, etc.)
Cell and content Styles/Formatting
Rich Text in cells
Conditional Formatting
Merged Cells
Hyperlinks
AutoFilter Ranges
Print Options
Freeze Panes
Embedded Images
Charts
Built-in Calculation engine for evaluating Excel formulae
5. File Formats
Reading Writing
BIFF (BIFF5 - BIFF 8)
MS Excel 95 and above (.xls .xlt)
OfficeOpenXML
MS Excel 2007 and above (Excel 2003 with Compatibility Pack) (.xlsx .xlsm .xltx
.xltm)
SpreadsheetML
MS Excel 2003 and above (.xml)
OASIS / Open Document Format
Open/Libre Office Calc (.ods .ots)
Gnumeric (.gnumeric)
SYLK
MS Multiplan Symbolic Link (.slk)
HTML
CSV
PDF
6. PHP Word Processing Engine
Major Features
Insert and format document sections
Insert and format Text elements
Insert Text breaks
Insert Page breaks
Insert and format Images and binary OLE-Objects
Insert and format watermarks
Insert Header / Footer
Insert and format Tables
Insert native Titles and Table-of-contents
Insert and format List elements
Insert and format hyperlinks
Template system
7. File Formats
Reading Writing
OfficeOpenXML
MS Word 2007 and above (MS Word 2003 with Compatibility Pack) (.docx)
OASIS / Open Document Format
Open/Libre Office Writer (.odt)
Rich-Text Format
.rtf
8. require_once '../src/PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->createSection();
// Add text elements
$section->addText('Hello World!');
$section->addTextBreak(2);
$section->addText('I am inline styled.', array('name'=>'Verdana', 'color'=>'006699'));
$section->addTextBreak(2);
$PHPWord->addFontStyle('rStyle', array('bold'=>true, 'italic'=>true, 'size'=>16));
$PHPWord->addParagraphStyle('pStyle', array('align'=>'center', 'spaceAfter'=>100));
$section->addText('I am styled by two style definitions.', 'rStyle', 'pStyle');
$section->addText('I have only a paragraph style definition.', null, 'pStyle');
// Save File
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save(str_replace('.php', '.docx', __FILE__));
9. PHP Presentation Library
Major Features
Presentation meta data (author, title, description, ...)
Add slides to presentation
Supports different fonts and font styles
Supports formatting, styles, fills, gradients, ...
Supports hyperlinks
Supports rich-text strings
Add images to your presentation
Set image styles
Set printing options
10. File Formats
Reading Writing
OfficeOpenXML
MS PowerPoint 2007 and above (MS PowerPoint 2003 with Compatibility Pack)
(.pptx)
OASIS / Open Document Format
Open/Libre Office Impress (.odp)
11. include 'PHPPowerPoint.php';
// Create new PHPPowerPoint object
$objPHPPowerPoint = new PHPPowerPoint();
// Set properties
$objPHPPowerPoint->getProperties()->setCreator('Mark Baker')
->setTitle('Office 2007 PPTX Test Document')
->setSubject('Office 2007 PPTX Test Document');
// Create slide
$currentSlide = $objPHPPowerPoint->getActiveSlide();
// Create a shape (drawing)
$shape = $currentSlide->createDrawingShape();
$shape->setName('PHPPowerPoint logo')
->setDescription('PHPPowerPoint logo')
->setPath('./images/phppowerpoint_logo.gif')
->setHeight(36)
->setOffsetX(10)
->setOffsetY(10);
// Create a shape (text)
$shape = $currentSlide->createRichTextShape()
->setHeight(300)
->setWidth(600)
->setOffsetX(170)
->setOffsetY(180);
$shape->getActiveParagraph()->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER );
$textRun = $shape->createTextRun('Thank you for using PHPPowerPoint!');
$textRun->getFont()->setBold(true)
->setSize(60)
->setColor( new PHPPowerPoint_Style_Color( 'FFC00000' ) );
// Save PowerPoint 2007 file
$objWriter = PHPPowerPoint_IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$objWriter->save(str_replace('.php', '.pptx', __FILE__));
14. PHPOffice
Contributions Welcome
Code Writing
Bug fixes
Patches
Extensions
New Features
New Readers
New Writers
Testing
Unit Tests
Testing against Office Suite programs
Documentation
API Document Blocks
Library Documents
Tutorials
Blog Posts
General
Answer questions on forums and message boards