15

Click here to load reader

What is PHPOffice?

Embed Size (px)

Citation preview

Page 1: What is PHPOffice?

Mark Baker

@Mark_Baker

Technical Team Lead at Inviqa(formerly Ibuildings UK)

Coordinator of Open Source libraries:PHPExcel, PHPWord, PHPPowerPoint, PHPVisio, PHPProject

Page 2: What is PHPOffice?

PHPOfficehttps://github.com/PHPOffice/

Set of PHP Libraries for creating, reading and writing documents in standard office suite file formats

PHPExcelPHPWordPHPPowerPointPHPProjectPHPVisio

Licensed under LGPL (GNU LESSER GENERAL PUBLIC LICENSE)

Page 3: What is PHPOffice?

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

Page 4: What is PHPOffice?

require_once '../Classes/PHPExcel.php';

$objReader = PHPExcel_IOFactory::createReader('Excel5');$objPHPExcel = $objReader->load("templates/invoiceTemplate.xls");

$data = array(array('title' => 'Excel for dummies', 'price' => 17.99, 'quantity' => 2 ), array('title' => 'PHP for dummies', 'price' => 15.99, 'quantity' => 1 ), array('title' => 'Inside OOP', 'price' => 12.95, 'quantity' => 1 ) );

$objPHPExcel->getActiveSheet()->setCellValue('D1', PHPExcel_Shared_Date::PHPToExcel(time()));

$baseRow = 5;foreach($data as $r => $dataRow) { $row = $baseRow + $r; $objPHPExcel->getActiveSheet()->insertNewRowBefore($row,1);

$objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $r+1) ->setCellValue('B'.$row, $dataRow['title']) ->setCellValue('C'.$row, $dataRow['price']) ->setCellValue('D'.$row, $dataRow['quantity']) ->setCellValue('E'.$row, '=C'.$row.'*D'.$row);}$objPHPExcel->getActiveSheet()->removeRow($baseRow-1,1);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');$objWriter->save(str_replace('.php', '.xls', __FILE__));

Page 5: What is PHPOffice?

File FormatsReading Writing

BIFF (BIFF5 - BIFF 8)MS Excel 95 and above (.xls .xlt)

OfficeOpenXMLMS Excel 2007 and above (Excel 2003 with Compatibility Pack) (.xlsx .xlsm .xltx .xltm)

SpreadsheetMLMS Excel 2003 and above (.xml)

OASIS / Open Document FormatOpen/Libre Office Calc (.ods .ots)

Gnumeric (.gnumeric)

SYLKMS Multiplan Symbolic Link (.slk)

HTML

CSV

PDF

Page 6: What is PHPOffice?

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

Page 7: What is PHPOffice?

File Formats

Reading WritingOfficeOpenXMLMS Word 2007 and above (MS Word 2003 with Compatibility Pack) (.docx)

OASIS / Open Document FormatOpen/Libre Office Writer (.odt)

Rich-Text Format.rtf

Page 8: What is PHPOffice?

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__));

Page 9: What is PHPOffice?

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

Page 10: What is PHPOffice?

File FormatsReading Writing

OfficeOpenXMLMS PowerPoint 2007 and above (MS PowerPoint 2003 with Compatibility Pack) (.pptx)

OASIS / Open Document FormatOpen/Libre Office Impress (.odp)

Page 11: What is PHPOffice?

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__));

Page 12: What is PHPOffice?

PHPProjectPlanned File Formats

Reading WritingGantt Project

MS Project Exchange

Page 13: What is PHPOffice?

PHPVisioPlanned File Formats

Reading WritingMS Visio

Dia

GraphViz

Page 14: What is PHPOffice?

PHPOfficeContributions 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

Page 15: What is PHPOffice?

PHPOfficehttps://github.com/PHPOffice/